Sunday, December 28, 2014

Angular JS: Services


Services, one of the most interesting thing in Angular JS. A service in angular terms means a set of code written especially to perform a specific task. These are singleton objects, that is to say, once defined, they can be used throughout the application and their values cannot be changed. Let’s take a simple example to demonstrate a simple service.

image

In order to consume the service, we need to pass the service’s instance into our controller which can be done as follows.

image

Once the service is instantiated, it can then be used to access the public methods and variable. Now when we will access the serviceCall property of our controller from View, the method helloTextGet() will get called which will return the text stored in the private variable helloText and pass it on to the view.

The View therefore would be like.

image

This is what we need to do tin order to create a rather simple service in Angular. Hope you would like the post.

Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

 
© 2013 Neelesh Vishwakarma
Posts RSS Comments RSS
Back to top