Académique Documents
Professionnel Documents
Culture Documents
Jaiswal, Rupal
Angularjs Controller
A controller is a JavaScript Object, created by a standard
JavaScript object constructor.
AngularJS application mainly relies on controllers to control the flow
of data in the application.
The ng-controller directive defines the application controller.
Controller accepts $scope as a parameter which refers to the
application
Scope
Scope is a special javascript object which plays the role of joining
controller with the views
Scope contains the model data. In controllers, model data is
accessed via $scope object.
Scopes provide context against which expression are evaluated.
All applications have a $rootScope which is the scope created on
the HTML element that contains the ng-app directive.
var app = angular.module('myApp', []);
app.run(function($rootScope) {
$rootScope.color = 'blue';
Scope Inheritance
Scope are controllers specific. If we defines nested controllers then
child controller will inherit the scope of its parent controller.
var mainApp = angular.module("mainApp", []);
mainApp.controller("shapeController", function($scope) {
$scope.message = "In shape controller";
$scope.type = "Shape";
});
mainApp.controller("circleController", function($scope) {
$scope.message = "In circle controller";
});
Events
AngularJS has its own HTML events directives.
An AngularJS event will not overwrite an HTML event, both events
will be executed.
ng-change
ng-click
ng-copy
ng-cut
ng-dblclick
ng-paste
Validation
Example
Expression
- Joshi,
Abhijeet
INTRODUCTION
Angular expressions are JavaScript-like code snippets. They bind
application data to a HTML element. Written inside two curly braces,
it reminds us of JavaScript expressions. Though Angular expressions
are different from JavaScript, it is an effort to bring JavaScript like
functionalities, such as, operators, variables, conditions etc to
HTML. You can assign values to the expressions, dynamically using
an Angular directive. This technique will spare you from assigning
static values and instead you can add different types of values
according to your choice.
Ternary Operator
A Ternary Operator in Angular is an alternative to if, else conditions in
JavaScript. Angular introduced this feature in its version 1.1.5. It is a
giant leap forward in making this framework, awesome.You can use the
ternary operator in expressions.
A Ternary operator takes three expressions. If the condition is true, it
will evaluate the first expression and it becomes the result. Else, it will
evaluate the second expression and that becomes the result.
Syntax
Condition ? first_expression : second_expression
Now, let us see an example.
},
},
},
}]">
One-time expressions will stop recalculating once they are stable, which
happens after the first execution if the expression result is a nonundefined value
When we declare an expression using :: , it tells Angular to ignore the
bind once a value is assigned to it. Angular will unbind it and any Model
updates wont affect the view. Consider it a render-once type method
rather than bind once.
Example
<!DOCTYPE html>
<html>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"
></script>
<body>
<div ng-app>
Name a City <input type="text" ng-model="city" />
<button ng-click="cityname = city" ng-init="city">Submit</button>
<p>One-time Binding: {{:: cityname}} </p>
<p>Normal Binding: {{ cityname}} </p>
</div>
</body>
Angular Services
- Sachdev,
Savin
AngularJS: Globalization
- Kumar,
Rajnish
Introduction
Lynda.com
Wikipedia
Developer Guide
Globalization = Internationalization + Localization
Internationalization (i18n) is the process of developing products in
such a way that they can be localized for languages and cultures
easily.
Localization (l10n), is the process of adapting applications and text to
enable their usability in a particular cultural or linguistic market.
For application developers, Internationalizing an application means
i18n example:
Summary
Text Formatting
Pluralization and Gender
Calendars
Dates, Numbers and Currencies
Font, Text sizes, width
and more
AngularJS Animations
- Purohit, Jay
Animation Basics:
-Animations concentrates on making a user interface better and give a
better look and feel which is more responsive in nature.
-AngularJS provides animation hooks for common directives such as
ngRepeat, ngSwitch, and ngView, as well as custom directives via the
$animate service.
-Trigger animations during the life cycle of various directives and when
triggered, will attempt to perform one of the following action depending
on if an animation is placed on the given directive.
-Animations are not available unless you include the
module as a dependency within your application
ngAnimate
Supported
Animation Events
ngRrepeat
ngView
ngInclude
ngSwitch
ngIf
ngClass
ngShow &
ngHide
JS FILE
angular.module('myApp', ['ngAnimate'])
.controller('ItemCtrl', function($scope) {
$scope.items = [ {name: "Lunchmeat"},{name: "Bread"},
{name: "Milk"},{name: "Mustard"},
{name: "Cheese"}
];
$scope.addItem = function() {
$scope.items.push($scope.item);
$scope.item = {};
};
$scope.removeItem = function(index) {$scope.items.splice(index,
1); };
});
HTML FIle
<ul>
<li ng-repeat="item in items" class="fade">
{{item.name}}
<span ng-click="removeItem($index)">X</span>
</li>
</ul>
<div class="row">
<div class="one-half column offset-by-three">
<input type="text" ng-model="item.name" />
<button class="button-primary" ng-click="addItem()">Add
Item</button>
Thanks.