Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问Angular中的子包对象_Angular_This_Viewchild - Fatal编程技术网

如何访问Angular中的子包对象

如何访问Angular中的子包对象,angular,this,viewchild,Angular,This,Viewchild,我在app.component.html中使用了一个包 <app-my-test2 *ngIf="data" #MyTest2Component></app-my-test2> 在将app-my-test2转换为package之前,所有操作都正常,我访问app-my-test2“this”,但是 将app-my-test2转换为package后,“this”返回未查找的问题是我的*ngIf。*ngIf指令正在终止我的控件组件,因此我无法引用它

我在app.component.html中使用了一个包

    <app-my-test2 *ngIf="data" #MyTest2Component></app-my-test2>
在将app-my-test2转换为package之前,所有操作都正常,我访问app-my-test2“this”,但是
将app-my-test2转换为package后,“this”返回未查找的问题是我的*ngIf。*ngIf指令正在终止我的控件组件,因此我无法引用它

前面提到的问题是导致视图未定义的ngIf。答案是使用ViewChildren而不是ViewChildren。我有类似的问题,我不希望网格显示,直到所有的参考数据已经加载

 @ViewChildren("MyTest2Component") public myTest2Component: QueryList<MyTest2Component>


public ngAfterViewInit() {

    this.myTest2Component.changes.subscribe((comps: QueryList <MyTest2Component>) =>
    {
        console.log(comps.first) ;
    });

}
@ViewChildren(“MyTest2Component”)公共MyTest2Component:QueryList
公共ngAfterViewInit(){
this.myTest2Component.changes.subscribe((comps:QueryList)=>
{
控制台日志(组件优先);
});
}

 @ViewChildren("MyTest2Component") public myTest2Component: QueryList<MyTest2Component>


public ngAfterViewInit() {

    this.myTest2Component.changes.subscribe((comps: QueryList <MyTest2Component>) =>
    {
        console.log(comps.first) ;
    });

}