N Sharma
N Sharma

Reputation: 34517

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.

Upvotes: 7

Views: 5413

Answers (2)

Pranav
Pranav

Reputation: 1646

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

Upvotes: 13

Ajay S
Ajay S

Reputation: 48622

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

Upvotes: 2

Related Questions