Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6: Property 'of' does not exist on type 'typeof Observable'

I am using Angular 6 using "rxjs": "^6.0.0",

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

import { Injectable } from '@angular/core';
import { TranslateLoader } from '@ngx-translate/core';
import { Observable, Subject, pipe, of } from 'rxjs';


@Injectable()
export class MiTranslateLoaderService implements TranslateLoader {

  getTranslation(lang: string): Observable<any> {
    return Observable.of({
      lbl_select: 'Select',
    });
  }
}
like image 455
HD.. Avatar asked Jun 15 '18 07:06

HD..


1 Answers

There are some updates in rxjs: ( Its rxjs6)

import { of } from 'rxjs';

It will work only when your app has rxjs-compat package installed

You can import of from rxjs:

import { Observable,of } from 'rxjs';

And simply return of()

 return of({
      lbl_select: 'Select',
    });

So your code will be:

import { Injectable } from '@angular/core';
import { TranslateLoader } from '@ngx-translate/core';
import { Observable, of } from 'rxjs';


@Injectable()
export class MiTranslateLoaderService implements TranslateLoader {

  getTranslation(lang: string): Observable<any> {
    return of({
      lbl_select: 'Select',
    });
  }
}
like image 130
Shubham Verma Avatar answered Oct 23 '22 01:10

Shubham Verma