我们可以在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) 如何将primeNG下拉宽度设置为在其容器内伸展100%?
它似乎有固定的element.style和.ui-dropdown {width:100%}覆盖不起作用.
<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)\npanels = [ {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
但没有成功。有人有任何解决方法吗?
我有一个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)