gpt4 book ai didi

angular - EventEmitter 已弃用,不应使用

转载 作者:太空狗 更新时间:2023-10-29 17:25:36 26 4
gpt4 key购买 nike

在 AngularDart 3.0.0 中,EventEmitter 已被弃用。那么,子组件如何向父组件发送事件呢?

更新之前是这样的:

@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。谁能举个例子?

最佳答案

只需使用一个普通的StreamController

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

.broadcast 是可选的。需要允许多个订阅者。

另见 https://www.dartlang.org/articles/libraries/broadcast-streams

关于angular - EventEmitter 已弃用,不应使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43680906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com