我正在嘗試訪問 childView 實例,但它一直說 childView 未定義。這是我的 childViews 代碼:@ViewChild(CreateQuestionnaireComponent,{ read: true, static: false }) private childQuestionnaireDialog:CreateQuestionnaireComponent;@ViewChild(ProjectNavbarComponent,{ read: true, static: false }) private childProjectNavBar:ProjectNavbarComponent;@ViewChild(QuestionnaireNodeComponent,{ read: true, static: false }) private childQuestionnaireNode:QuestionnaireNodeComponent;....onCreateTerminal() { this.childQuestionnaireDialog.generateQuestionnaireDropDownList(); this.childQuestionnaireDialog.resetFields(); this._hideQuestionnaireDialog = false; this._modalTitle = 'New Terminal'; this._placeHolderText = 'Terminal Questionnaire Title'; this._terminal = true; }...它說:this.childQuestionnaireDialog 是未定義的”。它正在使用 Angular 7。根據(jù)我的新知識,@viewChild 采用一個名為 static 的標志。如果我們將該標志設置為 true,則父組件會在其自己的創(chuàng)建過程中嘗試獲取對 childView 的引用。換句話說,我們可以在父組件的 onInit() 方法中有一個 childView 的實例?;旧鲜且淮卧L問,因為我們將無法在任何其他方法中訪問。設置為false的標志,基本上是ivy渲染器中的新方式。就我而言,這兩個選項都不起作用。
Angular 8 viewChild 返回未定義
函數(shù)式編程
2021-06-09 17:49:40