在我使用指令创建孙子之前,在使用指令之前一切都正常
*ngIf
在里面
grandchild
组件,
我试图找到解决办法,但没有找到解决这个问题的办法。
这是我的孙子指令
@Directive({
selector: 'grand-child-directive ',
})
export class gc{
@Input() name:string;
}
这是我的子组件ts
@Component({
selector: 'child-component',
templateUrl: './child-component.component.html',
styleUrls: ['./child-component.component.scss'],
})
export class childComponent implements AfterContentInit
@ContentChildren(GrandChildDirective) gc:QueryList<GrandChildDirective> ;
constructor(
) {
}
person:any[] = []
ngAfterContentInit() {
this.gc.toArray().map(item=>{
this.person.push(item)
})
}
}
这是孙辈模板
<div *ngFor="let prsn of person">
<a>prsn.name</a>
</div>
这是我要调用的模板代码
child
孙子
<child-component>
<grand-child-directive [name]='Ghandy' *ngIf="showGhandy"></grand-child-directive >
<grand-child-directive [name]='Ani' *ngIf="showAni"></grand-child-directive >
<grand-child-directive [name]='Budi' *ngIf="showBudi"></grand-child-directive >
</child-component>
这是我的ts
export class testComponent implements OnInit {
constructor() {
}
showGhandy= true
showAni= true
showBudi:boolean = true
ngOnInit(){
if(someCondition){
this.showGhandy = false
}
if(someCondition){
this.showAni= false
}
if(someCondition){
this.showBudi= false
}
}
}
即使情况是假的,也能看见人
我遗漏了什么吗?