为什么@output在角度2中不起作用? [英] why @output not working in angular 2?

查看:36
本文介绍了为什么@output在角度2中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以角度2将数据从一个组件发送到另一个组件.我的 @output无效.我正在列表中添加项目.单击 row .我正在将数据从一个组件发送到另一个组件.这是我的代码 https://plnkr.co/edit/sG6Suhnvc3Qmjmqjym67?p=preview

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

我喜欢这样

 @Output() userUpdated = new EventEmitter();

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

这不是为什么?

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

推荐答案

您缺少事件绑定 userUpdated 应该放在()方括号内

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.

更新后的矮人

更新1:您的插件中有一个 item.name 的错字

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

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

这篇关于为什么@output在角度2中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆