0
NgIf似乎永遠是真的,即使控制檯說錯誤。ngIf和@Input angular2奇數行爲
從以下組件的HTML
<product-component-tree itemSku="{{item.itemSku}}" selectable="false" classes="col-md-12 col-xs-12"></product-component-tree>
它設置選擇爲假的... ...
export class ProductComponentTree {
@Input() classes: string;
@Input() itemSku: string;
@Input() selectable: boolean;
ngOnInit() {
if (this.itemSku)
this.productDetailService.getComponents(this.itemSku, true).subscribe(x => {
this.treeData = x;
});
console.log(this.selectable); //prints false
}
}
的Html tmplate的組件:
<div class="{{classes}}" *ngIf="selectable">
something
<p-tree [value]="treeData" layout="horizontal" selectionMode="checkbox" [(selection)]="selectedProducts" (onNodeSelect)="nodeSelect($event)"></p-tree>
</div>
<div class="{{classes}}" *ngIf="!selectable">
else
<p-tree [value]="treeData" layout="horizontal" [contextMenu]="productTreeCm" selectionMode="single" [(selection)]="selectedProduct"></p-tree>
<p-contextMenu #productTreeCm [model]="items"></p-contextMenu>
</div>
始終顯示的東西在div在裏面!
目標: 它是否正常工作,並顯示其他div如果可選是假的。