6

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?

tenhobi
  • 1,977
  • 3
  • 23
  • 49
Cododoc
  • 125
  • 8

1 Answers1

7

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

Patrice Chalin
  • 15,440
  • 7
  • 33
  • 44
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • 2
    The 3.0.0 docs are out. Use of StreamController/Stream instead of EventEmitter is also illustrated in the docs under https://webdev.dartlang.org/angular/guide/template-syntax#custom-events – Patrice Chalin Apr 29 '17 at 00:03