EventEmitter is deprecated and shouldn't be used

此生再无相见时 提交于 2019-12-08 20:56:01

问题


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');
...

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


回答1:


Just use a normal StreamController

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

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

See also https://www.dartlang.org/articles/libraries/broadcast-streams



来源:https://stackoverflow.com/questions/43680906/eventemitter-is-deprecated-and-shouldnt-be-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!