First, What is AngularJS?
AngularJS makes it easier to develop a modern single-page application (Spas:single page applications).
- AngularJS binds application data to HTML elements.
- AngularJS can clone and repeat HTML elements.
- AngularJS can hide and display HTML elements.
- AngularJS can add code to the HTML element "behind".
- AngularJS supports input validation.
AngularJS is a JavaScript framework . It can be added to the HTML page by <script> tags.
AngularJS extends HTML through instructions , and binds data to HTML through an expression .
AngularJS is a JavaScript framework
AngularJS is a JavaScript framework. It is a library written in JavaScript.
AngularJS is published as a JavaScript file and can be added to a Web page via the script tag:
each angular.js version download: https://github.com/angular/angular.js/releases
ii. Examples of AngularJS
<! DOCTYPE html>
<meta charset= "Utf-8" >
<script src= "Http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js" >
</script>
<body>
<div ng-app= "" >
<p> name : <input type= "text" ng-model= "name" ></p>
</div>
</body>
Example Explanation:
when the page is loaded, The AngularJS is turned on automatically.
The ng-app directive tells the angularjs,<div> element to be the "owner" of the AngularJS application .
The ng-model directive binds the value of the input field to the application variable name.
The ng-bind directive binds the application variable name to the InnerHTML of a paragraph.
iii. AngularJS Directive
as you can see, The AngularJS directive is an HTML attribute prefixed with ng .
The ng-init directive initializes the AngularJS application variable.
AngularJS Instances
<div ng-app= "" ng-init= "Firstname= ' John '" >
<p> name is
<span ng-bind= "FirstName" >
</span>
</p>
</div>
|
HTML5 allows extended (self-made) properties to start with data- .
The AngularJS property starts with ng- , but you can use data-ng- to make the page work for HTML5.
|
with a valid HTML5:
AngularJS Instances
<div data-ng-app= "" data-ng-init= "Firstname= ' John '" >
<p> name is
<span data-ng-bind= "FirstName" >
</span>
</p>
</div>
iv. expression of AngularJS
The AngularJS expression is written in double curly braces:{{expression}}.
AngularJS expressions bind data to HTML, which is similar to the ng-bind directive.
AngularJS will "output" the data where the expression is written.
AngularJS Expressions are much like JavaScript expressions : They can contain literals, operators, and variables.
Example {{5 + 5}} or {{firstName + "" + LastName}}
<! DOCTYPE html>
<meta charset= "Utf-8" >
<script src= "Http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js" >
</script>
<body>
<div ng-app= "" > <p> my first expression: {{5 + 5}}</p>
</div>
</body>
v. Application of AngularJS
The AngularJS module defines the AngularJS application.
The AngularJS controller is used to control AngularJS applications.
Ng-app The directive defines the application and Ng-controller defines the controller.
AngularJS Instances
<div ng-app= "myApp" ng-controller= "Myctrl" >
name : <input type= "text" ng-model= "FirstName" ><br>
surname : <input type= "text" ng-model= "LastName" ><br> <br>
name : {{firstName + "" + LastName}}
</div>
<script>
var app = Angular.module (' myApp ', []); App.controller (' Myctrl ', function ($scope) {$scope. firstname= "John"; $scope. Lastname= "Doe";});
</script>
Angularjs First Knowledge