Skip to content
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

Query redesign #3922

Closed
11 of 12 tasks
rkirov opened this issue Aug 31, 2015 · 2 comments
Closed
11 of 12 tasks

Query redesign #3922

rkirov opened this issue Aug 31, 2015 · 2 comments
Assignees
Labels
breaking changes effort2: days refactoring Issue that involves refactoring or code-cleanup
Milestone

Comments

@rkirov
Copy link
Contributor

rkirov commented Aug 31, 2015

This is a proposal for a redesign for the query API. It allows a directive to find other directives that are structurally its 'children'.

  • A directive can query the children of the element it is placed on with @ContentChild / @ContentChildren (used to be @query) and its view with @ViewChild / @ViewChildren (used to be @ViewQuery).
  • When using @xxxChild the object received will be the desired element (or null if not found), when using @xxxChildren the object will be an ObservableArray.
  • Queries will be recalculated when a structural change occurs (ng-if, ng-for), @xxxChild will be set to the new value, while @xxxChildren will notify via the observable API.
  • The results will not be injectable, but rather set on declared properties by the framework.

Ex:

@Component(...)
@View(...) 
class ListComponent {
  @ContentChild(ItemDirective)
  itemDirective: ItemDirective;
 }

@Component(...)
@View(...) 
class ListComponent2 {
  @ViewChildren(ItemDirective)
  itemDirectives: ObservableArray<ItemDirective>;
 }

The children directives will be set before the following callbacks are fired (#3863) - afterContentChecked for ContentChild and afterViewChecked for ViewChild.

Both query mechanisms do not go into further into component subviews. ContentChild / ContentChildren support configurable visibility as follows :

  • descendants: true - all content descendants are considered
  • descendants: false - only direct children of the querying directive are considered (default)
    ViewChildren has no visibility configuration. Queries always skip the element on which the querying directive lives (similar to DOM.querySelector).

Implementation

// cc @mhevery @vsavkin

@vsavkin
Copy link
Contributor

vsavkin commented Oct 26, 2015

The only thing that is left is to remove the old API.
#4919

@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes effort2: days refactoring Issue that involves refactoring or code-cleanup
Projects
None yet
Development

No branches or pull requests

5 participants