why @output not working in angular 2?

2019-09-17 11:46发布

问题:

I am trying send data from one component to another in angular 2 . my @output is not working.I am adding item in list .On click of row . I am sending data from one component to another. here is my code https://plnkr.co/edit/sG6Suhnvc3Qmjmqjym67?p=preview

I do like this,

 @Output() userUpdated = new EventEmitter();

liClick(item){
      this.userUpdated.emit(item)
  }

this is not fired why ?

 userSelected(items){
    alert(items);
    this.title="user is selected" +item.name;
  }

回答1:

You were missing event binding userUpdated should be inside ( ) brackets

<app-home [userItems]="items" (userUpdated)="userSelected($event)"></app-home>

And you had some typo errors.

Updated plunker

Update 1 : you had a typo there item.name was there in your plunker

 this.title="user is selected" +items.name;


标签: angular