I searched and explored regarding my question but I didn't get the appropriate answer, I am new in angular 2, exploring and creating a demo app with the help of angular's official doc. ( https://angular.io/docs/ts/latest/tutorial/toh-pt6.html ). Now I reached HTTP section. Here I am not able to understand what is observable and why it is used?
Can anyone please let me know why Observable used in below code?
search(term: string): Observable<Hero[]> {
return this.http
.get(`app/heroes/?name=${term}`)
.map(response => response.json().data as Hero[]);
}
why here also ?:
import { Hero } from './hero';
export class HeroSearchComponent implements OnInit {
heroes: Observable<Hero[]>;
}
I am still confused for promise and observable . What is the difference between promise and observable ? And why they chose Observable ?