Monday, April 6, 2015

An Angular app -- implementing Rest Service call and a String Reversal Angular Filter

Spring MVC Rest API and AngularJs together really makes appealing frontend for a Single Page Application


What Is Angular?

AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Angular's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology.
https://docs.angularjs.org/guide/introduction


Agenda :

1.) To write a Angular Controller, calling Rest Endpoint implemented in the past blog
2.) To write a Angular Filter as an intro(ex taken from Angular docs)
3.) Call the Angular Components in HTML


Create a file "Custcontroller.js" in the testjs folder under webapp Dir -


angular.module- To declare An Angular Module

Controller -  Controller is nothing but a JavaScript constructor function that we will attach to HTML DOM.

$scope : We create Scope variables to be used in the HTML page withing the scope of Controller

Filter: Formats the value of Expression in HTML page


Now, we will bind this Angular components to HTML page




In the above HTML page we load Angular CDN  in Script src from -"https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"




ng-app : it's an Angular Directive which  bootstraps the Angular JS application(in shot make Angualr available) ,
So, if you define ng-app="my-app" in the body it makes that particular Angular module available through out the body in html page or you can define in one div tag and can restrict the availibility.

ng-controller - This directive attaches the controller to View.

ng-model- The directive bind the property( input,select ,textarea etc) on to the scope


Concusion:

Using the Above the example you can design a simple web application -- using a Response from Rest API.



for any questions write me at jsapan4@gmail.com