import { Injectable } from '@angular/core';
import 'rxjs/add/observable/of';
import { Observable } from 'rxjs/Observable';
import { AppSettings } from "./appsettings";
@Injectable()
export class AppSettingsService {
getSettings(): Observable<AppSettings> {
let settings = new AppSettings();
return Observable.of<AppSettings>(settings);
}
}
上面是我的angular5代码,但是我遇到了问题。请参阅控制台错误图片。
答案 0 :(得分:1)
该错误是因为从版本6开始,rxjs的软件包结构已更改。以下代码适用于Angular 6:
import { Injectable } from '@angular/core';
import { Observable , of} from 'rxjs';
import { AppSettings } from "./appsettings";
@Injectable({
providedIn: 'root'
})
export class AppSettingsService {
getSettings(): Observable<AppSettings> {
let settings = new AppSettings();
return of<AppSettings>(settings);
}
}