Angular and new RxJS import system

peryztor

I updated rxjs to 6.1.0. And I want to refactor my imports to new style. I mean:

import { Observable, of } from 'rxjs';

But this is gave me an error:

// return Observable.of(data); 
error TS2339: Property 'of' does not exist on type 'typeof Observable'.

map import wokrs (I think)

import { map } from 'rxjs/operators';

return this.http.post(url, data).pipe(
    map(res => res)
)

What should I do?

i also append my dependencies

"@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"

and my 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"
Vikas

Previously

 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));

In RXJS:6 syntax has changed and import too Instead of Observable.of use of

import { Observable, of } from 'rxjs';

const source = of(1, 2, 3, 4, 5);

const subscribe = source.subscribe(val => console.log(val));

Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to import .refCount() in rxjs / angular

Angular 6 RXJS Import Syntax?

Typescript import syntax with Angular / Rxjs

How to import rxjs timer in angular 6?

Angular rxjs Observable.timer is not a function with import

Unable to import 'rxjs' into angular 5 application

Import new library - Angular 5

Angular 6 handling of 403 response with new RxJS

import an angular 5 module with rxjs into an angular 8 app

Using rxjs in angular 2 component, should I manually import the operators?

Angular/rxjs: Why don't I have to import toPromise anymore?

How to import a new font into a project - Angular 5

Angular2 rxjs/Subject import - can't load vendor/rxjs/index.js

How can I subscribe or merge new Observable in RXJS and Angular

Angular, RxJs - dynamic new observable with user reaction as resolve

Angular 4 RxJs Observable Subjects array not updating with new object

Angular Compile Error rxjs when create new app

Angular RxJS add data from new observable to current observable

How to import RxJS merge?

RxJS: How to import Just

rxjs Observable import issue

System.import comes from JavaScript or is specific to angular 2

Angular 2 : System.import() : Not working with full path

Can't import firestore and firebase in angular 8 for an auth system

Angular TS1003 Identifier expected on throw import statement, my error stems from the import of throw from 'rxjs'

angular 5, RxJs { map } import doesn't work or i'm missing something?

What is the best practice/right way to include rxjs store in angular2/4, is it supposed to be in bootstrap or import?

Angular 5 rxjs 5.5.2 - import of interval error - "Cannot read property 'call' of undefined"

Proper import pattern for pipeable RxJs operators using Angular CLI/WebPack rollup