Angular - Cannot find name 'Observable' - Solved

By Hardik Savani May 2, 2024 Category : Angular

Here, I will show you how to works angular cannot find name 'observable '. I’m going to show you about cannot find name 'observable' angular 13. We will use cannot find name observable angular. you'll learn angular cannot find name observable error.

You can use this example with angular 8, angular 9, angular 10, angular 11, angular 12, angular 13, angular 14, angular 15, angular 16 and angular 17 version.

When i was working on my on side project. I was creating one service and i forget to import observable, so i found following error:

"Cannot find name 'Observable'"

Then i search on google and find out solution we need to import 'observable' from rxjs library. you can see below solution and full service code as well.

Solution:

Import following line on your service file, ts file etc where you used Observable.

import { Observable } from 'rxjs';

Code: src/app/post.service.ts

import { Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';

import { Observable } from 'rxjs';

import { Post } from './post';

@Injectable({

providedIn: 'root'

})

export class PostService {

private url: string = 'https://jsonplaceholder.typicode.com/posts';

constructor(private httpClient: HttpClient) { }

public getPosts(): Observable{

return this.httpClient.get(this.url);

}

}

I hope it can help you...

Tags :
Shares