Skip to content

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

Merged
mmalerba merged 1 commit into
angular:masterfrom
Wykks:patch-1
Apr 1, 2019
Merged

fix(schematics): use ngAfterViewInit instead of ngOnInit in table#15446
mmalerba merged 1 commit into
angular:masterfrom
Wykks:patch-1

Conversation

@Wykks

@Wykks Wykks commented Mar 12, 2019

Copy link
Copy Markdown
Contributor

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

@devversion devversion left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
Contributor

@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
Copy Markdown
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
Copy Markdown

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