在filter
管道处获取打字稿错误:
this
的
void
上下文无法分配给方法的this
类型Observable<{}>
代码:
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import { Injectable } from '@angular/core';
import { share } from "rxjs/operators/share";
import { filter } from 'rxjs/operator/filter';
import * as m from '../../models/app.models';
@Injectable()
export class SharedService {
observable: Observable<any>;
observer: Observer<any>;
constructor() {
var temp = Observable.create((observer: Observer<any>) => {
this.observer = observer;
});
this.observable = temp.share();
}
broadcast(event: m.SharedEventModel) {
this.observer.next(event);
}
on(eventName, callback) {
return this.observable.pipe(filter(x => x.Name === eventName)).subscribe(callback); <-- Error
}
}
RxJs版本:5.5.2