Wednesday, June 13, 2018

Predefined Services

**** Predefined Services ****

- The Services given by angular framework called as Predefined Services.


Predefined Services in Angular2:
---------------------------------------

1) Http
- Http is the predefined class in angular2.

- Http Class used to connect to servers via "http protocol".

- Http Class avaiable in "@angular/http" package.

- Http Class belongs to "HttpModule".

- HttpModule also available in "@angular/http" package.

- when ever we hit the server we are getting the "Observable" Response.

- map() is the predefined function used to catch the positive Observable Response.

- catch() is the predefined function used to catch the Negative Observable Response.

- "Positive Observable Response" is the "Response" Type.

- map(),catch() and next() functions are available in "rxjs/Rx" package.

- Observable also available in "rxjs" package.


Ex_1:


Step 1:
create the Angular6 Application

> ng new serEx1

- automatically "serEx1" project will be created.



Step 2:
create the custom service by using following command.


> ng g s services/countries

g stands for generate.

s stands for service


******************************************
serEx1
     src
app
          services
countries.service.ts
countries.service.spec.ts
******************************************

countries.service.ts
--------------------


No comments:

Post a Comment