考虑这个子组件:
@Component({
selector: 'mySelector',
template: `<ion-spinner [ngIf]="ngif"></ion-spinner>`
})
export class MyDirective {
ngif: boolean;
constructor() {}
@Input() serverWaiting:boolean = true;
@HostBinding('ngIf')
ngOnChanges() {
this.ngif = !this.serverWaiting ? true : null;
}
Run Code Online (Sandbox Code Playgroud)
主机组件的模板:
<mySelector [serverWaiting]></mySelector>
Run Code Online (Sandbox Code Playgroud)
主机组件:
@Component({
templateUrl: 'hostComp.html',
directives: [myDirective]
})
export class HostComp {
serverWaiting = true;
}
Run Code Online (Sandbox Code Playgroud)
然而,Spinner没有显示.知道我做错了什么吗?
资料来源:https://angular.io/docs/ts/latest/api/common/index/NgIf-directive.html
angular ×1