Angular JS
Angular JS is a Jawa script framework that extend HTML with new attributes. Angular JS is perfect for single phase applications. To mark an HTML element as a container for an angular JS application, write the attribute NG-app.
For example
<div ng-app="">
Angular JS can be added to an HTML page with a <script> tags.
Angular JS has attributes called directives.
The ng-model directive binds the value of HTML input control to application data.
The ng-bind directive binds application data to the HTML.
Angular JS is a MVVM (Model View View Model) framework because it binds MOdel to teh VIew and View to the model using ng-model and ng-bind
<div ng-app="gaurav">
<p> Name:
<input type="text" ng-model="name" />
</p>
<p ng-bind="name"></p>
</div>
<div ng-app="shirodkar" ng-init="firstName='John'">
<p> The name is <span ng-bind="firstName"></span></p>
</div>
Anugular JS expresions are written inside curly braces {{ expression }}.
Angular JS will "output" data exactly where the application is written.
<div ng-app="Gaurav">
<p>My first expression is: {{ 5 + 5 }}</p>
</div>
<div ng-app="">
<p>Name:
<input type="text" ng-model="name" />
</p>
<p>{{ name }} </p>
</div>
Angular JS controllers provide the functionality whenever a event occurs.
Events may be anything like storing data, clicking of a button, updating $scopen object, listening to a url with or without query parameters, making AJAX calls and so on.
<div ng-app="Gaurav">
<'div ng-controller="gaurav-controller">
</div>
</div>
let app = angular.module("Gaurav",[]);
app.controller("gaurav-controller",
function($scope) {
$scope.firstName = "Gaurav";
$scope.lastName = "Shirodkar";
}
);
Inserting expressions in HTML
<div ng-app="" ng-init="myCol='lightblue'">
<input type="text" style="background-color:{{myCol}}" ng-model="myCol" />
</div>
Angular JS numbers are like Java Script numbers
<div ng-app="" ng-init="quantity=10;cost=5;">
<p>Total in dollar: {{ quantity * cost }}
</p>
</div>
Same example using ng-bind
<div ng-app="" ng-init="quantity=10;cost=5">
<p>Total in dollar: <span ng-bind='quantity * cost"></span></p>
</div>
AngularJS strings
<div ng-app="" ng-init="firstName='Gaurav';lastName='Shirodkar''>
<p> The full name is {{ firstName + " " + lastName }}</p>
</div>
Same example using ng-bind:
<div ng-app="" ng-init="firstName='Gaurav';lastName='Shirodkar'">
<p>The name is <span ng-bind="firstName + ' ' + lastName"></span>
</div>
ANgular JS objects are like JAvascript objects.
<div ng-app="" ng-init="person={firstName='Gaurav',lastname='Shirodkar'}">
<p>The name is {{ person.lastName }}</p>
Comments
Post a Comment