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

QueryList not iterable in constructor #3577

Closed
ericmartinezr opened this issue Aug 10, 2015 · 1 comment
Closed

QueryList not iterable in constructor #3577

ericmartinezr opened this issue Aug 10, 2015 · 1 comment
Assignees

Comments

@ericmartinezr
Copy link
Contributor

Sorry for the vague title.

This is a simple thing but I was suggested to post this as an issue by another user.

Whenever you want to access a QueryList (by Query [directives] or ViewQuery [components]) you can't iterate over the list in the constructor. If you print the list you see the results, but they are not iterable. If you iterate over them in onInit (for example) it works like it should. If this is the expected behaviour it should be documented for others users may struggle with this issue.

See this example code

@Component({
  selector : 'main-component'
})
@View({
  template : `<another-component #anothercmp></another-component>`,
  directives : [AnotherComponent]
})
class MainComponent {
  constructor(@ViewQuery('#anothercmp') anotherCmp: QueryList) {

    // It prints the results under '_results'
    console.log(anotherCmp);

    this.anotherCmp = anotherCmp;

    // But they aren't iterable
    // Nothing is printed
    for(let an of anotherCmp) {
      an.doSomething();
    }
  }
  onInit() {

    // Here there is no problem, everything works like a charm
    for(let an of this.anotherCmp) {
      an.doSomething();
    }
  }
}

Not a coding issue, but documentation. Here's a repro for both directives and components.

Edit : Just now I found this issue #2916 where is explained why this happens, but still, it should be documented.

@rkirov rkirov assigned rkirov and mhevery and unassigned rkirov Aug 11, 2015
mhevery added a commit to mhevery/angular that referenced this issue Aug 11, 2015
BREAKING CHANGE:

Closes angular#3577
mhevery added a commit to mhevery/angular that referenced this issue Aug 11, 2015
mhevery added a commit to mhevery/angular that referenced this issue Aug 11, 2015
mhevery added a commit to mhevery/angular that referenced this issue Aug 11, 2015
mhevery added a commit to mhevery/angular that referenced this issue Aug 12, 2015
mhevery added a commit that referenced this issue Aug 12, 2015
BREAKING CHANGE:

Closes #3577
mhevery added a commit that referenced this issue Aug 12, 2015
BREAKING CHANGE:

Closes #3577
mhevery added a commit that referenced this issue Aug 12, 2015
BREAKING CHANGE:

Closes #3577
mhevery added a commit that referenced this issue Aug 12, 2015
BREAKING CHANGE:

Closes #3577
mhevery added a commit that referenced this issue Aug 12, 2015
BREAKING CHANGE:

Closes #3577
mhevery added a commit that referenced this issue Aug 12, 2015
BREAKING CHANGE:

Closes #3577
mhevery added a commit to mhevery/angular that referenced this issue Aug 13, 2015
mhevery added a commit that referenced this issue Aug 13, 2015
BREAKING CHANGE:

Closes #3577
@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 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants