小编McL*_*Lac的帖子

在angular2视图模板中传递枚举

我们可以在angular2视图模板中使用枚举吗?

<div class="Dropdown" dropdownType="instrument"></div>
Run Code Online (Sandbox Code Playgroud)

传递字符串作为输入:

enum DropdownType {
    instrument,
    account,
    currency
}

@Component({
    selector: '[.Dropdown]',
})
export class Dropdown {

    @Input() public set dropdownType(value: any) {

        console.log(value);
    };
}
Run Code Online (Sandbox Code Playgroud)

但是如何传递枚举配置?我在模板中想要这样的东西:

<div class="Dropdown" dropdownType="DropdownType.instrument"></div>
Run Code Online (Sandbox Code Playgroud)

什么是最佳做法?

编辑:创建一个例子:

import {bootstrap} from 'angular2/platform/browser';
import {Component, View, Input} from 'angular2/core';

export enum DropdownType {

    instrument = 0,
    account = 1,
    currency = 2
}

@Component({selector: '[.Dropdown]',})
@View({template: ''})
export class Dropdown {

    public dropdownTypes = DropdownType;

    @Input() public set dropdownType(value: any) {console.log(`-- dropdownType: ${value}`);};
    constructor() …
Run Code Online (Sandbox Code Playgroud)

enums angular2-template angular

91
推荐指数
3
解决办法
5万
查看次数

primeNG p-dropdown伸缩100%

如何将primeNG下拉宽度设置为在其容器内伸展100%?

它似乎有固定的element.style.ui-dropdown {width:100%}覆盖不起作用.

css primeng

19
推荐指数
3
解决办法
2万
查看次数

如何在 primeNg p-splitter 中动态添加分割面板?

<p-button label="Add" (click)="onAddPanel()"></p-button>\n <p-splitter [style]="{'height': '100px'}" styleClass="p-mb-5">\n  <ng-container  *ngFor="let panel of panels">\n    <ng-template pTemplate>\n      <div class="p-col p-d-flex p-ai-center p-jc-center">\n          {{panel.name}}\n      </div>\n    </ng-template>\n  </ng-container>\n</p-splitter>\n
Run Code Online (Sandbox Code Playgroud)\n
panels = [ {name: 'Panel1'}, {name: 'Panel2'}, {name: 'Panel3'} ];\n\nonAddPanel() {\n    this.panels = [...this.panels, ...[{name: `Panel${this.panels.length+1}`}] ];\n}\n
Run Code Online (Sandbox Code Playgroud)\n

如何绑定p-splitter到新集合并在事件触发时添加面板onAddPanel?\n我尝试过\xe2\x80\x9cprimeng\xe2\x80\x9d: \xe2\x80\x9c12.0.0\xe2\x80\x9d但没有成功。有人有任何解决方法吗?

\n

splitter primeng angular

6
推荐指数
1
解决办法
1606
查看次数

Angular2 - ngFor指令不映射已删除的项目

我有一个Item容器和项目模式,其中应该添加子项目并从其容器中删除.添加很好,而删除什么都不做.当删除任何子项时,angular2*ngFor指令似乎不起作用.

    import { NgFor} from 'angular2/common';
    import { bootstrap } from 'angular2/platform/browser';
    import { Component, View, Directive, OnDestroy, Input, enableProdMode } from 'angular2/core';
    import { CORE_DIRECTIVES} from 'angular2/common';


    @Component({selector: 'itemcontainer',})
    @View({ template: `<ul (click)="$event.preventDefault()">
                       <li *ngFor="#it of items">Any Item</li>
                       </ul>
                       <div><ng-content></ng-content></div>`,

            directives: [NgFor],
    })
    export class ItemContainer {
        public items: Array<Item> = [];

        public addItem(item: Item) {
            this.items.push(item);
        }

        public removeItem(item: Item) {
            var index = this.items.indexOf(item);
            if (index === -1) {
                return;
            }

            console.log(`Index about to remove: ${index} this.items …
Run Code Online (Sandbox Code Playgroud)

angular

5
推荐指数
2
解决办法
7463
查看次数

标签 统计

angular ×3

primeng ×2

angular2-template ×1

css ×1

enums ×1

splitter ×1