不推荐使用EventEmitter,不应该使用 [英] EventEmitter is deprecated and shouldn't be used

查看:100
本文介绍了不推荐使用EventEmitter,不应该使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AngularDart 3.0.0中,不推荐使用EventEmitter.那么,如何将事件从子组件发送到父组件?

In AngularDart 3.0.0 EventEmitter is deprecated. So, how to send event from child component to parent?

在更新之前,它看起来像:

Before update it is looks like:

@Component(
  selector: 'my-test',
  templateUrl: 'test.component.html'
)
class TestComponent {
  @Input()
  String name = '';

  @Output()
  EventEmitter<String> onNameChange = new EventEmitter<String>();
}

...    
onNameChange.emit('New Name');
...

现在我需要使用Stream和StreamController.有人可以举个例子吗?

Now I need use Stream and StreamController. Can someone give an example?

推荐答案

只需使用普通的StreamController

final _onNameChangeController = new StreamController<String>.broadcast();
@Output()
Stream<String> get onNameChange => _onNameChangeController.stream;

.broadcast是可选的.必须允许多个订阅者.

.broadcast is optional. It is required to allow multiple subscribers.

另请参见 https://www.dartlang.org/articles/libraries/broadcast-流

这篇关于不推荐使用EventEmitter,不应该使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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