EventEmitter is deprecated and should not be used

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

Before updating, it looks like this:

@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 to use Stream and StreamController. Can someone give an example?

+6
source share
1 answer

Just use regular StreamController

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

.broadcastis optional. You need to allow multiple subscribers.

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

+7
source

Source: https://habr.com/ru/post/1016859/


All Articles