question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ViewChild undefined in AoT

See original GitHub issue

Hi, 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: '&#10004;'}">
		<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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
zolaktcommented, Mar 28, 2018

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.

2reactions
talesportocommented, Oct 31, 2018

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found