angular - 属性 'of' 在类型 'typeof Observable 上不存在

标签 angular

<分区>

我最近在我的身份验证 token 上使用了 observable,例如

Observable.of('token');

但它一直给我上面提到的错误,尽管我已经导入了它。

import {Observable} from 'rxjs/Observable';

最佳答案

你需要导入它:

对于 Angular >= 6.0.0

使用 RxJS 6.0.0 Angular Changelog 6.0.0

import { of } from 'rxjs';

它的用法已经改变,你不再从 Observable 中调用它:

of('token');

RxJS v5.x to v6 Update Guide - HowTo: Convert to pipe syntax它使用 of()

对于 Angular <= 5.x.xx

import 'rxjs/add/observable/of';

它在你的问题中使用

Observable.of('token');

关于angular - 属性 'of' 在类型 'typeof Observable 上不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38067580/

相关文章:

Angular 5 在路由更改之前添加事件

javascript - 错误 : Template parse errors: Can't bind to 'options' since it isn't a known property of 'chart'

angular - ionic 列表 vs ionic 滚动 vs ionic 3 中的 virtualScroll

angular - 如何获取 Angular 2 中的日期格式?

javascript - Angular.js 2 : Access component of a directive

angular - 如何在 angular2 中使用 @ContentChildren 选择超过 1 种类型

javascript - ionic 2 订单列表

javascript - Angular-redux 设计 - 数组选择器

javascript - 处理 Angular 2 中动态创建的组件的 @Input 和 @Output

Angular 2 : passing object with nested object to child component