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.
Simply return of(data) and not Observable.of(data)
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With