Angular 和新的 RxJS 导入系统
Angular and new RxJS import system
我将 rxjs 更新到 6.1.0。我想将我的导入重构为新样式。我的意思是:
import { Observable, of } from 'rxjs';
但这给了我一个错误:
// return Observable.of(data);
error TS2339: Property 'of' does not exist on type 'typeof Observable'.
map import wokrs(我认为)
import { map } from 'rxjs/operators';
return this.http.post(url, data).pipe(
map(res => res)
)
我该怎么办?
我还附加了我的依赖项
"@agm/core": "1.0.0-beta.2",
"@angular/animations": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"brace": "0.11.0",
"codemirror": "5.33.0",
"core-js": "^2.5.4",
"dragula": "3.7.2",
"moment": "2.20.1",
"ngx-quill": "2.0.4",
"rxjs": "^6.1.0",
"rxjs-compat": "^6.1.0",
"spinkit": "1.2.5",
"ts-helpers": "1.1.2",
"zone.js": "^0.8.26"
和我的 devDependencies
"@angular-devkit/build-angular": "~0.6.0",
"@angular/cli": "~6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/language-service": "^6.0.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "^2.7.2"
现在是:
import { of } from 'rxjs/observable/of';
以前
import 'rxjs/add/observable/of';
// or
import { of } from 'rxjs/observable/of
const source = Observable.of(1, 2, 3, 4, 5);
const subscribe = source.subscribe(val => console.log(val));
在 RXJS:6 中,语法已更改并导入,而不是 Observable.of
使用 of
import { Observable, of } from 'rxjs';
const source = of(1, 2, 3, 4, 5);
const subscribe = source.subscribe(val => console.log(val));
我将 rxjs 更新到 6.1.0。我想将我的导入重构为新样式。我的意思是:
import { Observable, of } from 'rxjs';
但这给了我一个错误:
// return Observable.of(data);
error TS2339: Property 'of' does not exist on type 'typeof Observable'.
map import wokrs(我认为)
import { map } from 'rxjs/operators';
return this.http.post(url, data).pipe(
map(res => res)
)
我该怎么办?
我还附加了我的依赖项
"@agm/core": "1.0.0-beta.2",
"@angular/animations": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"brace": "0.11.0",
"codemirror": "5.33.0",
"core-js": "^2.5.4",
"dragula": "3.7.2",
"moment": "2.20.1",
"ngx-quill": "2.0.4",
"rxjs": "^6.1.0",
"rxjs-compat": "^6.1.0",
"spinkit": "1.2.5",
"ts-helpers": "1.1.2",
"zone.js": "^0.8.26"
和我的 devDependencies
"@angular-devkit/build-angular": "~0.6.0",
"@angular/cli": "~6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/language-service": "^6.0.0",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "^2.7.2"
现在是:
import { of } from 'rxjs/observable/of';
以前
import 'rxjs/add/observable/of';
// or
import { of } from 'rxjs/observable/of
const source = Observable.of(1, 2, 3, 4, 5);
const subscribe = source.subscribe(val => console.log(val));
在 RXJS:6 中,语法已更改并导入,而不是 Observable.of
使用 of
import { Observable, of } from 'rxjs';
const source = of(1, 2, 3, 4, 5);
const subscribe = source.subscribe(val => console.log(val));