Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property 'of' does not exist on type 'typeof Observable'

I am building an Angular5 project where I have to use http. I am using observable here, but when I am using 'of'

 scope.fetchApi = Observable.of(data);

then it is giving me an error:

Property 'of' does not exist on type 'typeof Observable'. 

I had imported 'rxjs/add/observable/of'; also, but same error was there. I had also tried import { Observable } from 'rxjs/Observable'; but it was throwing an error:

Module '"eclipse:angular5-example/node_modules/rxjs/Observable"' has no exported member 'Observable'.

You can see my code as below:

import { Component, OnInit } from '@angular/core';
import { UserService } from './app.service';
import { FetchApi } from '../models/fetch-api.model';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import  'rxjs/add/observer/of';

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

  fetchApi: Observable<FetchApi[]>;

  constructor(private router: Router, private userService: UserService) {


  }

  ngOnInit() {
     const scope = this;
    this.userService.getUsers()
      .subscribe( data => {
         scope.fetchApi = Observable.of(data);
        //this.fetchApi = data;
      });
  };



}

Please shed some light on it.

like image 568
N Sharma Avatar asked Jun 09 '18 16:06

N Sharma


2 Answers

Simply return of(data) and not Observable.of(data)

like image 70
Pranav Avatar answered Nov 08 '22 14:11

Pranav


Read this https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md

import paths has been changed.

import { Observable, of } from 'rxjs';
like image 23
Ajay S Avatar answered Nov 08 '22 14:11

Ajay S