0
我有2个兄弟姐妹组件Angular2:如何输入通过与* ngIf Angular2组件参考
<test1 *ngIf="data" [data] = "makes" #test1R></formModel>
<testing *ngIf="data" [test1Ref]="test1R"></testing>
组件“测试”具有调用test1的组件的功能的功能:
export class Testing{
@Input() test1Ref: test1Component;
constructor() { }
testFunction($event){
this.test1Ref.hello();
}
我的问题是this.test1Ref
未定义,因为test1组件具有* ngIf(<test1 *ngIf="data"
),
但没有* ngIf我在输入值([data] = "makes"
)的test1组件中有错误。
如何通过组件参考* ngIf
哦,我明白了,我不喜欢,因为如果我用异步调用检索数据,检查是否存在中的数据ngInit总是没用,所以我必须处理一些事件? – LorenzoBerti
已更新的答案显示如何处理异步的空检查。 – Baconbeastnz
好的,谢谢! :) – LorenzoBerti