Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
AngularJS
Data Binding
Prepared By
Santhanam
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Template Engine
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
One way data binding
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Two way data binding (AngularJS)
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Expressions
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com

Expressions are used to bind application data to
HTML

Expressions are written inside double braces
like {{ expression }}

For example, valid expressions in Angular are:

1+2

a+b

user.name

items[index]
• In JavaScript, trying to use undefined properties
or methods generates ReferenceError or
TypeError. In AngularJs, it will not show any
error or warning.
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Modules
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com

Modules are used to separate logics say
services, controllers, application etc. and keep
the code clean.

A module is created by using the AngularJS
function angular.module
<div ng-app="myApp">...</div>
<script>
var app = angular.module("myApp", []);
</script>
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Controllers
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com

Controller is attached to the DOM via the ng-
controller directive

A new child scope will be created and made
available as an injectable parameter to the
Controller's constructor function as $scope

Use controllers to:
– Set up the initial state of the $scope object
– Add behavior to the $scope object
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Set up the initial state of the $scope object
var myApp = angular.module('myApp',[]);
myApp.controller('GreetingController', ['$scope',
function($scope) {
$scope.greeting = 'Hola!';
}]);
Template
<div ng-controller="GreetingController">
{{ greeting }}
</div>
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Add behavior to the $scope object
var myApp = angular.module('myApp',[]);
myApp.controller('DoubleController', ['$scope',
function($scope) {
$scope.double = function(value) {
return value * 2;
};
}]);
Template
<div ng-controller="DoubleController">
Two times <input ng-model="num"> equals {{ double(num) }}
</div>
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
Dependency Injection (DI)
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com

Dependency Injection is a software design pattern in which
components are given their dependencies instead of hard coding
them within the component.

This helps in making components reusable, maintainable.

AngularJS provides following components which can be injected
into each other as dependencies
– value
– factory
– service
– provider
– constant
Website : http://www.softsolutions4u.com Email : info@softsolutions4u.com
angular.module('myModule', [])
.factory('serviceId', ['depService',
function(depService) {
// ...
}])
.directive('directiveName', ['depService',
function(depService) {
// ...
}])
.filter('filterName', ['depService',
function(depService) {
// ...
}]);

Angular data binding by Soft Solutions4U

  • 1.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com AngularJS Data Binding Prepared By Santhanam
  • 2.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Template Engine
  • 3.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com One way data binding
  • 4.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Two way data binding (AngularJS)
  • 5.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Expressions
  • 6.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com  Expressions are used to bind application data to HTML  Expressions are written inside double braces like {{ expression }}  For example, valid expressions in Angular are:  1+2  a+b  user.name  items[index] • In JavaScript, trying to use undefined properties or methods generates ReferenceError or TypeError. In AngularJs, it will not show any error or warning.
  • 7.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Modules
  • 8.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com  Modules are used to separate logics say services, controllers, application etc. and keep the code clean.  A module is created by using the AngularJS function angular.module <div ng-app="myApp">...</div> <script> var app = angular.module("myApp", []); </script>
  • 9.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Controllers
  • 10.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com  Controller is attached to the DOM via the ng- controller directive  A new child scope will be created and made available as an injectable parameter to the Controller's constructor function as $scope  Use controllers to: – Set up the initial state of the $scope object – Add behavior to the $scope object
  • 11.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Set up the initial state of the $scope object var myApp = angular.module('myApp',[]); myApp.controller('GreetingController', ['$scope', function($scope) { $scope.greeting = 'Hola!'; }]); Template <div ng-controller="GreetingController"> {{ greeting }} </div>
  • 12.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Add behavior to the $scope object var myApp = angular.module('myApp',[]); myApp.controller('DoubleController', ['$scope', function($scope) { $scope.double = function(value) { return value * 2; }; }]); Template <div ng-controller="DoubleController"> Two times <input ng-model="num"> equals {{ double(num) }} </div>
  • 13.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com Dependency Injection (DI)
  • 14.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com  Dependency Injection is a software design pattern in which components are given their dependencies instead of hard coding them within the component.  This helps in making components reusable, maintainable.  AngularJS provides following components which can be injected into each other as dependencies – value – factory – service – provider – constant
  • 15.
    Website : http://www.softsolutions4u.comEmail : info@softsolutions4u.com angular.module('myModule', []) .factory('serviceId', ['depService', function(depService) { // ... }]) .directive('directiveName', ['depService', function(depService) { // ... }]) .filter('filterName', ['depService', function(depService) { // ... }]);