LoginComponent.html:18 ERROR TypeError: Observable.Observable.of is not a function
at LogConsole.webpackJsonp../node_modules/angular-logger/angular-logger.umd.js.LogConsole.log (angular-logger.umd.js:142)
at LogService.webpackJsonp../node_modules/angular-logger/angular-logger.umd.js.LogService.writeToLog (angular-logger.umd.js:351)
at LogService.webpackJsonp../node_modules/angular-logger/angular-logger.umd.js.LogService.fatal (angular-logger.umd.js:311)
at LoginComponent.webpackJsonp../src/app/user/login/login.component.ts.LoginComponent.hi (login.component.ts:83)
at Object.eval [as handleEvent] (LoginComponent.html:18)
at handleEvent (core.js:13254)
at callWithDebugContext (core.js:14739)
at Object.debugHandleEvent [as handleEvent] (core.js:14326)
at dispatchEvent (core.js:9703)
at core.js:10317
我在使用自定义记录器库的应用程序中收到此错误。
login.component.ts:
hi(){
alert('hi!');
this.logService.fatal('hi there!');
}
最终在我的自定义记录器库中调用以下函数,这是导致错误的原因:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import { LogPublisher } from './log-publisher.class';
import { LogEntry } from './log-entry.class';
export class LogConsole extends LogPublisher {
log(record: LogEntry) : Observable<boolean> {
console.log(record.buildLogString());
return Observable.of(true);
}
}
我尝试更改“&#39;”的导入网址。运营商,没有成功。
自定义记录器库中的rxjs版本是
"dependencies": {
"rxjs": "~5.5.0"
}
并且消费应用中的版本是:
"rxjs": "~5.5.0"
答案 0 :(得分:3)
您应该使用较新版本的调用Rxjs方法:
""
然后:
import {of} from 'rxjs/observable/of';
更新rxjs版本6:
return of(true);