Skip to content

Calling appViewManager.getComponentView thrown NPE rather then returning null on non component ElementRef #2890

Closed

Description

@mhevery
@ng.Directive({
  selector: '[probe]'
})
class Probe {
  constructor(public appViewManager: ng.AppViewManager, public elementRef: ng.ElementRef) {
  }

  onInit() {
    // INCCORRECT USAGE! Should return null rather then throw.
    console.log(this.appViewManager.getComponentView(this.elementRef));
  }
}


@ng.Component({
  selector: 'au-greeter'
})
@ng.View({
  directives: [ng.NgFor, Probe],
  template: `
  <ul probe>
    <li *ng-for="var item of items">
      <div></div>
      {{item}}
    </li>
  </ul> 
  `
})
class App {
  items = ['a', 'b', 'c'];
  user: string;

  constructor(public appViewManager: ng.AppViewManager, public elementRef: ng.ElementRef) {
    this.user = 'World';
    // CORRECT USAGE!
    console.log(this.appViewManager.getComponentView(this.elementRef));
  }

  greet() {
    alert('Hello ' + this.user + '!');
  }
}



 ng.bootstrap(App);```

Activity

  1. tbosch commented on Jul 10, 2015

    @tbosch
    Contributor

    Note: While refactoring the compiler because of the new content projection, this method will go away...

  2. tbosch commented on Jul 14, 2015

    @tbosch
    Contributor

    Closing this, as it will be removed via #2839

  3. angular-automatic-lock-bot commented on Sep 6, 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.

  4. locked and limited conversation to collaborators on Sep 6, 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

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions