ViewChild undefined in AoT
See original GitHub issueHi, I’m having an issue with AoT build in version 3.0.0 Here is a streamlined code sample
<aw-wizard navBarLayout="large-empty-symbols" navBarLocation="left">
<aw-wizard-step stepTitle="Step1" [navigationSymbol]="{symbol: '1'}">
<button class="btn btn-primary" type="button" awNextStep>Continue</button>
</aw-wizard-step>
<aw-wizard-step stepTitle="Step2" [navigationSymbol]="{symbol: '2'}">
<button class="btn btn-primary" type="button" awPreviousStep>Previous step</button>
<button class="btn btn-primary" type="button" awNextStep>Continue</button>
</aw-wizard-step>
<aw-wizard-step stepTitle="Step3" [navigationSymbol]="{symbol: '3'}">
<button class="btn btn-primary" type="button" awPreviousStep>Previous Step</button>
<button class="btn btn-success" type="button" (click)="finish()">Order</button>
</aw-wizard-step>
<aw-wizard-completion-step stepTitle="Finish" [navigationSymbol]="{symbol: '✔'}">
<p>Thank you for ordering!</p>
</aw-wizard-completion-step>
</aw-wizard>
export class TestComponent{
@ViewChild(WizardComponent) wizard: WizardComponent;
model: any;
constructor(private service: TestService){}
finish(): void {
this.service.create(this.model).subscribe((res: any) => {
this.wizard.navigation.goToNextStep();
});
}
}
The code is simplified, but those are the only important parts. In the last step I have to wait for a response from a service, and move the wizard programmatically only if it was successful.
In development, with JiT compiler it works as expected.
In production, with AoT compiler, this.wizard
is always undefined, and it never moves to the completion step.
Any suggestions or workaround? Thanks
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:12 (4 by maintainers)
Top Results From Across the Web
ReferenceError X (ViewChild ) is not defined when compile ...
I declared my ViewChild inside .ts file and inside .html file I set local variable like this <div #nameColumnHeader></div> Is there an expected ......
Read more >ViewChild - Angular
Property decorator that configures a view query. The change detector looks for the first element or the directive matching the selector in the...
Read more >Component Queries Metadata Appears To Be Broken When ...
ASIDE: I know that there were recent changes to the way the ViewChild() annotation can be defined. However, this same behavior is also...
Read more >cannot read properties of undefined (reading 'filter') angular
1. As requested, here is a better explaination (did not have place in comments) Cannot read properties of undefined (reading 'filter') This means...
Read more >[Solved]-Using @ViewChild to get hold of the .nativeElement ...
Coding example for the question Using @ViewChild to get hold of the .nativeElement of an input returns 'undefined'-angular.js.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After some testing… It seems to work with
@ViewChild('wizard') wizard: WizardComponent
and<aw-wizard navBarLayout="large-empty-symbols" navBarLocation="left" #wizard>
Don’t know if ts an issue with in this lib or AoT compiler itself, although this is the first time I encountered this problem. Maybe worth properly testing and referencing in the docs.
I change it:
@ViewChild(WizardComponent) public wizard: WizardComponent;
to it:
@ViewChild('wizard') public wizard: WizardComponent;
and works using
ng build --prod --build-optimizer
Tks @zolakt !!! I believe we need to add it to the documentation!