2016-06-30 62 views
1

我使用angular2 rxjs來測試它的組播FUNC,這裏是我的代碼:angular2類型「主題<{}>」是不能分配給輸入「()=>主題<number>」

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>' 
+2

嘗試'無功受=新主題();' – yurzui

回答

5

的參數一樣@yurzui說,你需要定義根的類型埃裏克主題

var subject = new Subject<number>(); 
+0

哦,謝謝,我真的很愚蠢...... – shun

相關問題