Skip to content

fix(schematics): use ngAfterViewInit instead of ngOnInit in table #15446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2019

Conversation

Wykks
Copy link
Contributor

@Wykks Wykks commented Mar 12, 2019

According to the offical doc of Angular, view queries are set before the ngAfterViewInit callback is called.
https://angular.io/api/core/ViewChild
ngOnInit works with the current version of Angular, but it can change in the future.

According to the offical doc of Angular, view queries are set before the ngAfterViewInit callback is called.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Mar 12, 2019
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. This right now works as the queries are considered as static by the Angular compiler.

Also it's brittle to make this assumption in a schematic as it's not guaranteed to be always static. e.g. if someone adds a ngIf, the query turns dynamic.

LGTM from my side. waiting for Andrew to also have a look.

@andrewseguin
Copy link
Contributor

This looks fine since data is not set before view initialization. If it was, the table would render all the rows before view initialization is complete, and then correct itself after the sort/paginator is set.

@jelbourn
Copy link
Member

@andrewseguin is that a formal approval?

@andrewseguin andrewseguin added pr: merge safe action: merge The PR is ready for merge by the caretaker labels Mar 28, 2019
@andrewseguin
Copy link
Contributor

Yes it is - added the labels

@mmalerba mmalerba merged commit 7b603c5 into angular:master Apr 1, 2019
jelbourn pushed a commit that referenced this pull request Apr 4, 2019
…5446)

According to the offical doc of Angular, view queries are set before the ngAfterViewInit callback is called.
https://angular.io/api/core/ViewChild
ngOnInit works with the current version of Angular, but it can change in the future.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants