我是Observables的新手.我如何从一个简单的字符串创建Observable?然后订阅它并在它改变时输出它.
原文链接:https://www.f2er.com/angularjs/141322.html那有意义吗?
My constructor on service constructor() { // Create observable stream to output our data this.notice = Observable.create( (observer) => this.observer = observer; ); }; My method on service set(string) { this.notice.subscribe((value) => { // Push the new value into the observable stream this.observer.next(string); },(error) => console.log('Could not set data.')); } Calling service method setNotice(event) { event.preventDefault(); // Calling service to set notice this.noticeService.set('This is a string'); }
我想我在这里做错了什么?但不知道该怎么问.我将不胜感激任何解释.