Skip to content

Missing forwardRef in ViewChild/ViewChildren should throw #4489

Closed

Description

@ericmartinezr

Follow up of #4174

I'm updating this issue to a38, still reproducible. I added an issue with @ViewChild that returns null instead when there's no forwardRef.

@View({
  template : `
  <child></child>
  <child></child>
  `,
  directives: [forwardRef(() => Child)]
})
class Parent implements AfterViewInit {

  // Length : 2
  //@ViewChildren(forwardRef(() => Child)) children: QueryList<Child>;

  // Length : 0
  @ViewChildren(Child) children: QueryList<Child>;

  // Returns the child
  //@ViewChild(forwardRef(() => Child)) child : Child;

  // Returns null
  @ViewChild(Child) child : Child;

  afterViewInit() {
    console.log(this.child);
    console.log(this.children);
  }
}

@Component({selector : 'child'})
@View({template : 'I\'m a child!'})
class Child {}

Again, I assume that ContentChild/ContentChildren works the same way that ViewChild/ViewChildren so I didn't test the issue against both of them.

Repro http://plnkr.co/edit/zWmKMQ

Activity

  1. mgechev commented on Oct 6, 2015

    @mgechev
    Member

    Same issue is valid for ContentChildren and ContentChild as well. I'm working on this issue.

  2. ericmartinezr commented on Apr 27, 2016

    @ericmartinezr
    ContributorAuthor
  3. mgechev commented on Apr 27, 2016

    @mgechev
    Member

    I can take this one next week or the week after ng-conf.

  4. added a commit that references this issue on Jun 4, 2016
    b5e484a
  5. added a commit that references this issue on Jun 5, 2016
    057abef
  6. angular-automatic-lock-bot commented on Sep 8, 2019

    @angular-automatic-lock-bot

    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.

  7. locked and limited conversation to collaborators on Sep 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions