我使用angular2 rxjs来测试它的多播功能,这是我的代码:
var source = Observable.from([1, 2, 3]);
var subject = new Subject();
var multicasted = source.multicast(subject);
// These are, under the hood, `subject.subscribe({...})`:
multicasted.subscribe({
next: (v) => console.log('observerA: ' + v)
});
multicasted.subscribe({
next: (v) => console.log('observerB: ' + v)
});
// This is, under the hood, `source.subscribe(subject)`:
multicasted.connect();
我收到了错误信息:
类型'主题< {}>'不能分配给
类型的参数'Subject<number> | (() => Subject<number>)'.
Type 'Subject<{}>' is not assignable to type '() => Subject<number>'.
Type 'Subject<{}>' provides no match for the signature '(): Subject<number>'
答案 0 :(得分:6)
var subject = new Subject<number>();