In my last blog, Basic AngularJS with Routing [Part 1], I discussed AngularJS Controllers with examples. In this blog, I delve into Directive and Services.
Directives – Introduction
We have used some Directives previously with Angular, i.e. Directives such as ng-app and ng-controller. Now, in this blog, I want to show you a few other useful Directives, like the Directive to handle button clicks and the Directive to move user input into my JavaScript model. These Directives allow you to build interactive webpages that not only display data, but also react to the user and become a little more dynamic. We will build something that lets the user search, sort, and browse code repositories.
ng-model, ng-click
Output:
ng-repeat
Output:
ng-show and hide
If user model is not empty then user details will be displayed.
Services
A service in Angular is a component that performs a specific job, like providing a timer, or providing the ability to communicate over HTTP. We have seen that component and used it; it is the $http service. Services are very important concepts where it will be initiated only once for an application.