【问题标题】:Why should we use eventemitter together with @output in angular?为什么我们应该在 Angular 中将 eventemitter 和 @output 一起使用?
【发布时间】:2022-10-04 19:50:12
【问题描述】:

为什么我们应该在 Angular 中将 eventemitter 和 @output 一起使用?为什么 @input 不需要 eventemitter ?

标签: angular


【解决方案1】:

好吧,一个简单的反应是,在孩子中,您有机会知道输入值何时更改(使用 onChange 挂钩)。

但是,在父母中,您需要对事件(可以发出或不发出值)做出反应。

这说角度:

子组件使用@[Output](https://angular.io/api/core/Output)() 属性来引发事件以通知父级更改。要发起活动,请发送@[Output](https://angular.io/api/core/Output)() 必须具有[EventEmitter](https://angular.io/api/core/EventEmitter) 的类型 ,这是@angular/core 中的一个类 用于发出自定义事件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    • 2017-07-09
    • 2022-07-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 2020-10-09
    相关资源
    最近更新 更多