0
我想創建一個指令,刪除/添加自己像* ngIf會做的DOM。我至今是:如何在我的指令主機中使用* ngIf?
@Directive({
selector: '[myDirective]',
host: {
'[hidden]': 'hidden',
}
})
export class MyDirective {
constructor(private myService : MyService) {
}
hidden() {
return !this.myService.valid;
}
但我需要的是這樣的:
@Directive({
selector: '[myDirective]',
host: {
'*ngIf': 'hidden',
}
})
...
可悲的是,我不能在指令host
使用'*ngIf': 'hidden'
。我得到的錯誤是:
Can't bind to 'ngIf' since it isn't a known property of 'button'.
也'[ngIf]': 'hidden'
不起作用。
那麼,如何在指令中使用ngIf?
指令不能動態添加/刪除。 –
Günter的評論^應該是被接受的答案 – balu