Angular Ntroduction

AngularJS Introduction


AngularJS is a JavaScript framework. It tin live added to an HTML page amongst a <script> tag.
AngularJS extends HTML attributes amongst Directives, in addition to binds information to HTML amongst Expressions.

AngularJS is a JavaScript Framework

AngularJS is a JavaScript framework. It is a library written inwards JavaScript.
AngularJS is distributed equally a JavaScript file, in addition to tin live added to a spider web page amongst a script tag:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

AngularJS Extends HTML

AngularJS extends HTML amongst ng-directives.
The ng-app directive defines an AngularJS application.
The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.
The ng-bind directive binds application information to the HTML view.

AngularJS Example

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="">
  <p>Name: <input type="text" ng-model="name"></p>
  <p ng-bind="name"></p>
</div>

</body>
</html>
Example explained:
AngularJS starts automatically when the spider web page has loaded.
The ng-app directive tells AngularJS that the <div> chemical cistron is the "owner" of an AngularJS application.
The ng-model directive binds the value of the input acre to the application variable name.
The ng-bind directive binds the innerHTML of the <p> chemical cistron to the application variable name.

AngularJS Directives

As you lot convey already seen, AngularJS directives are HTML attributes amongst an ng prefix.
The ng-init directive initializes AngularJS application variables.

AngularJS Example

<div ng-app="" ng-init="firstName='John'">

<p>The mention is <span ng-bind="firstName"></span></p>

</div>
Alternatively amongst valid HTML:

AngularJS Example

<div data-ng-app="" data-ng-init="firstName='John'">

<p>The mention is <span data-ng-bind="firstName"></span></p>

</div>
You tin exercise data-ng-, instead of ng-, if you lot desire to brand your page HTML valid.
You volition acquire a lot to a greater extent than near directives afterward inwards this tutorial.

AngularJS Expressions

AngularJS expressions are written within double braces: {{ aspect }}.
AngularJS volition "output" information precisely where the aspect is written:

AngularJS Example

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="">
  <p>My offset expression: {{ five + five }}</p>
</div>

</body>
</html>
AngularJS expressions bind AngularJS information to HTML the same agency equally the ng-bind directive.

AngularJS Example

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="">
  <p>Name: <input type="text" ng-model="name"></p>
  <p>{{name}}</p>
</div>

</body>
</html>
You volition acquire to a greater extent than near expressions afterward inwards this tutorial.

AngularJS Applications

AngularJS modules define AngularJS applications.
AngularJS controllers command AngularJS applications.
The ng-app directive defines the application, the ng-controller directive defines the controller.

AngularJS Example

<div ng-app="myApp" ng-controller="myCtrl">

First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
});
</script>
AngularJS modules define applications:

AngularJS Module

var app = angular.module('myApp', []);
AngularJS controllers command applications:

AngularJS Controller

app.controller('myCtrl', function($scope) {
    $scope.firstName= "John";
    $scope.lastName= "Doe";
});


Comments

Popular posts from this blog

What Are The Main Components of a Computer System

How To Provide View’S Every Mo Information Inwards Codeigniter?

How To Integrate Google Adwords Api Into Codeigniter?