Angular-cli: Impossible d'importer Observable depuis 'rxjs/Observable'

Created on 21 May 2018  Â·  12Comments  Â·  Source: angular/angular-cli

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

secondes: number;

constructor (){

}

ngOnInit() {

const counter = Observable.interval(1000);
counter.subscribe(
  (value: number) => {
    this.secondes = value;
  },
  (error: any) => {
    console.log('Erreur !!!');
  },
  () => {
    console.log('Observable complete !');
  }
);

}

}

terminal

ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve 'rxjs/Observable' in '/Volumes/DONNEES PE/PROJETS/ANGULARJS/val/src/app'
ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve 'rxjs/Rx' in '/Volumes/DONNEES PE/PROJETS/ANGULARJS/val/src/app'
ℹ 「wdm」: Failed to compile.
ERROR in node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.
node_modules/rxjs/Rx.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat'.
src/app/app.component.ts(2,10): error TS2305: Module '"/Volumes/DONNEES PE/PROJETS/ANGULARJS/val/node_modules/rxjs/Observable"' has no exported member 'Observable'.

Most helpful comment

Merci infiniment pour vos reponses j'ai remplace ma ligne de code const counter = Observable.interval(1000); par const counter = interval(1000); et tout fonctionne.

All 12 comments

besoin d"aide svp !

What versions of angular and rxjs are you using?

Angular CLI 6.0.3

version de rxjs : 6.0.0

RxJs 6 import syntax is:

import { Observable, Subject } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';

merci a vous j'ai fait les deux importations donc vous m'avez suggere . mais voici une autre erreur.

ERROR in src/app/app.component.ts(22,32): error TS2339: Property 'interval' does not exist on type 'typeof Observable'.

import { Observable, Subject, interval } from 'rxjs';

If you're coming from Rxjs 5.5. This might be a good read: https://github.com/ReactiveX/rxjs/blob/master/MIGRATION.md

Desole j'ai ajoute l'importation proposee mais toujours la meme erreur.

code:

import { Component, OnInit } from '@angular/core';
import { Observable, Subject, interval } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

secondes: number;

constructor (){

}

ngOnInit() {

const counter = Observable.interval(1000);
counter.subscribe(
  (value: number) => {
    this.secondes = value;
  },
  (error: any) => {
    console.log('Erreur !!!');
  },
  () => {
    console.log('Observable complete !');
  }
);

}

}

erreur :
ERROR in src/app/app.component.ts(22,32): error TS2339: Property 'interval' does not exist on type 'typeof Observable'.

const counter = interval(1000);

Merci infiniment pour vos reponses j'ai remplace ma ligne de code const counter = Observable.interval(1000); par const counter = interval(1000); et tout fonctionne.

try this I found it in an other thread and it resolved my problem
npm install rxjs@6 rxjs-compat@6 --save

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

5amfung picture 5amfung  Â·  3Comments

JanStureNielsen picture JanStureNielsen  Â·  3Comments

jmurphzyo picture jmurphzyo  Â·  3Comments

rajjejosefsson picture rajjejosefsson  Â·  3Comments

delasteve picture delasteve  Â·  3Comments