Angular - Cannot find name 'Observable' - Solved
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Angular setInterval() and clearInterval() Example Tutorial
- Angular Simple Pagination Example | ngx-pagination
- Angular 13 RxJS Observable with Httpclient Example
- Angular 13 Image Upload with Preview Tutorial
- Angular 13 Reactive Forms Validation Tutorial Example
- Angular Material Datepicker Disable Previous Dates Example
- Angular 11 RxJS Observable Example
- Angular HttpClient with Observable Example
- Angular HttpClient Delete Example | Angular Http Delete Request Example
- Angular HttpClient Get Example | Angular Http Get Request Example
- Angular Service with Httpclient Example
- Angular Http Post Request Example