ViewChild and ngIf directive

34 views
Skip to first unread message

Reza Razavipour

unread,
Oct 2, 2018, 11:17:26 PM10/2/18
to Angular and AngularJS discussion
Angular CLI6 

In my component, I have:

@ViewChild('necRiskAnalysisDialog')
private necRiskAnalysisDialog;

at some point I make a call to this.necRiskAnalysisDialog.set(...

In my html, I have 
<div>
<div *ngIf="someCondition">
<nec-risk-analysis #necRiskAnalysisDialog></nec-risk-analysis>
</div>
</div>

I get a undefined for necRiskAnalysisDialog  in the line where I say this.necRiskAnalysisDialog.set

How do I get around this?

Sander Elias

unread,
Oct 2, 2018, 11:50:20 PM10/2/18
to Angular and AngularJS discussion
Hi Reza,

Have a look at @ViewChilden. There is a change observable that fires when the view changes.

Regards
Sander

Reza Razavipour

unread,
Oct 3, 2018, 12:03:35 AM10/3/18
to ang...@googlegroups.com
I see that now Sander,

thank you
Reza


--
You received this message because you are subscribed to a topic in the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/Bgj2_Anc_D0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages