相关疑难解决方法(0)

Angular2中的主机绑定ngIf

考虑这个子组件:

@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

3
推荐指数
1
解决办法
3658
查看次数

标签 统计

angular ×1