EventEmitter is deprecated and shouldn't be us

2019-06-20 01:44发布

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条回答
Anthone
2楼-- · 2019-06-20 02:03

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

查看更多
登录 后发表回答