Angular 无法与“一起工作”;“的;“的类别”;rxjs“;
我写了Angular 无法与“一起工作”;“的;“的类别”;rxjs“;,angular,rxjs,Angular,Rxjs,我写了ValueService课程,如下所示 import { Injectable } from '@angular/core'; import { of } from 'rxjs'; import { delay } from 'rxjs/operators'; @Injectable() export class ValueService { protected value = 'real value'; getValue() { return thi
ValueService
课程,如下所示
import { Injectable } from '@angular/core';
import { of } from 'rxjs';
import { delay } from 'rxjs/operators';
@Injectable()
export class ValueService {
protected value = 'real value';
getValue() {
return this.value;
}
getObservableValue() {
return of('Observable value');
}
getPromiseValue() {
return Promise.resolve('Promise value');
}
getObservableDelayValue() {
//return of('Observable delay value').pipe(delay(100));
return of('Observable delay value').pipe(delay(1000));
}
}
但是,在错误之下无法前进
src/app/demo/demo.ts(3,10)中的错误:错误TS2305:Module“H:/Ashok/JasmineLearnings/JasminePractice/node_modules/rxjs/Rx”没有导出的成员“of”
在谷歌搜索,但没有运气。有谁能帮我解决这个问题吗,因为我没有太多同事的支持。怎么样
import { of } from 'rxjs/observable/of';
错误很明显。'rxjs'
中没有导出的'of'
运算符请尝试导入:
import { of } from 'rxjs/observable/of';
首先,如果您是第一次使用rxjs,那么我建议检查
package.json
中的rxjs
依赖项
"dependencies": {
"@angular/animations": "^5.2.8",
"@angular/cdk": "^5.2.5",
"@angular/common": "^5.2.8",
"@angular/compiler": "^5.2.8",
"@angular/core": "^5.2.8",
"@angular/forms": "^5.2.8",
"@angular/http": "^5.2.8",
"@angular/platform-browser": "^5.2.8",
"@angular/platform-browser-dynamic": "^5.2.8",
"@angular/router": "^5.2.8",
"@ng-bootstrap/ng-bootstrap": "^1.0.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
然后执行
npm缓存清理
和npm安装
您必须执行几个步骤:1.你可以用
import { of } from 'rxjs/observable/of';
代替
import { of } from 'rxjs';
b、 )在项目位置上打开命令提示符,并键入以下代码: npm
安装rxjs
并点击回车键c、 )运行项目,然后检查问题是否已解决。
d、 )您也可以在相同的命令提示符下安装rxjs compat,并键入以下代码
npm install rxjs-compat
按enter键并重复步骤d您必须按原样导入。从“rxjs/observable/of”导入{of};您使用的是什么版本的rxjs?您确定错误来自此代码段而不是代码库中的其他地方吗?谢谢您的回答。有没有人知道“of”类可以在“rxjs/observable”下使用,而“delay”类可以在“rxjs/operators”下使用?检查这里:如果你选择了一个操作符,总会有一个例子,如何导入它