5
I updated my angular 5.2.10 project to angular 6.
I did step by step https://update.angular.io/
, everything is OK unless Observable.from
In a service I used Observable.from(this.user)
as following:
import { Observable } from 'rxjs/Observable';
...
Observable.from(this.users)// this.users is an array
It was OK, but in angular 6 the following error occurred
Property 'from' does not exist on type 'typeof Observable'
I changed it as follows
import { Observable, from } from 'rxjs';
But no change and error occurred again!
- 1you can also fix these upgrade issues using a TSLint rules for RxJs:
npm i -g rxjs-tslint
rxjs-5-to-6-migrate -p tsconfig.json
– Mobiletainment Jun 14 '18 at 21:49
3 Answers 正确答案
13
In rxjs@6 you can use from
as standalone function:
import { from } from 'rxjs';
...
from(this.users);
or
import { from as observableFrom } from 'rxjs';
...
observableFrom(this.users);
See also migration to rxjs6 guide
- just out of curiosity, is not the same? stackoverflow.com/questions/47003112/… – Sajeetharan May 5 '18 at 6:31
1
Without modifying the existing code, still you will be able to run just by installing "rxjs-compat" package.
npm install rxjs-compat --save
0
This is changed from previous rxjs versions to rxjs6. (RxJS v5.x to v6 Update Guide)
Before rxjs 6
import { Observable } from "rxjs";
let numbers = [1, 5, 10];
let source = Observable.from(numbers);
With rxjs 6
import { from, Observable } from "rxjs";
let numbers = [1, 5, 10];
let source = from(numbers);