文章内容
2020/5/26 14:55:22,作 者: 黄兵
Observable.of is not a function
最近在写Angular日志记录功能的时候,出现了如下错误:
Observable.of is not a function
具体代码如下:
export class LogConsole extends LogPublisher { log(record: LogEntry): Observable<() => boolean> { // Log to console console.log(record.buildLogString()); return Observable.of(() => true); }
出现问题的原因:
由于代码更新,原来的写法已经不适用。
解决方案:
在Angular 6/rxjs 6中,需要这样修改:
首先需要这样导入:
import { of } from 'rxjs';
之后这样使用:
of(res);
参考资料:
1、Observable.of is not a function
黄兵个人博客原创。
评论列表