Thursday 16 November 2017

typescript - Observable in angular 2 ?

style="font-weight: bold;">

Answer




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. ( href="https://angular.io/docs/ts/latest/tutorial/toh-pt6.html" rel="nofollow
noreferrer">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 {
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;
}


I
am still confused for promise and observable . What is the difference between promise
and observable ? And why they chose Observable ?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...