Angular Js Introduction
Angular Js Introduction
http://professional-guru.com
Philosophy
“ANGULARJSis what HTML could have been if it had been designed for webapplicationdevelopment.”
“”ANGULARJSis built around the philosophy that declarative code is better than imperative code whilebuilding
UIsand wiring different components of webapplicationtogether.”
<!doctype html>
<html ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter aname here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html> http://professional-guru.com
Why ANGULARJS?
• EnhancesHTML by attaching directives, custom tags, attributes, expressions, templates within HTML.
• Encourage TDD
• Code Reuse
http://professional-guru.com
Key Features of ANGULARJS
• ReusableComponents
• Expressions
• MVC/MVVM Design Pattern
• Filters
• Dependency Injection
• Directives
• End to end Integration Testing / UnitTesting
• Form Validation
• Routing
http://professional-guru.com
MVC : Model View Controller
View :
• Renders the Modeldata
• Send User actions/events to controller
• UI
View
3. Implement the
BusinessLogic on
1. Event or User Action
response data and
or View Load
Bind it to View
Controller:
Model:
• BusinessLogic Model Controller • Define Application Behavior
• Maps user actions to Model
• Notify view changes • Select view for response
• Application Functionality
• Data in general
UI
View
• User actions,commands
• Data binding
• Notifications
BusinessLogic PresentationLogic
and Data Model ViewModel
• Data Access
• Update ViewModel about change
http://professional-guru.com
ng-app
<html ng-app>
http://professional-guru.com
HTML Compiler
Angular's HTML compiler allows the developer to teach the browser new HTML syntax. The compiler allows
you to attach behavior to any HTML element or attribute and even create new HTML elements or attributes
withcustombehavior.Angularcallsthesebehavior extensionsdirectives.
Compiler is an angular service whichtraversesthe DOM looking for attributes. Thecompilation process
happens in two phases.
Compile: traverse the DOM and collect all of the directives. Theresult is alinkingfunction.
Link: combine the directives with ascope and produce alive view.Any changes in the scope model are
reflected in the view,and any user interactions with the vieware reflected in the scope model. This makes
the scope model the single source of truth.
http://professional-guru.com
http:/ / docs.angularjs.org/guide/ compiler
Directive
<input ng-model='name'>
http://professional-guru.com
Expression
Expressions are JavaScript-like code snippets that are usually placed in bindings such as{{
expression }}
<body>
1+2={{1+2}}
</body>
http://professional-guru.com
Forms
Form and controls provide validation services, so that the user can be notified of invalid
input. This provides a better user experience, because the user gets instant feedback on
howto correctthe error.
http://professional-guru.com
Module
/ / declare amodule
http://professional-guru.com
Routing
It Isused for deep-linking URLsto controllers and views(HTML partials). It watches$location.url() and
tries to map the path to an existing route definition.
$routeProvider.when('/Book',{
template: 'examples/book.html',
controller: BookCntl,
});
$routeProvider.when('/Book/chapter01', {
template: 'examples/chapter01.html',
controller: ChapterCntl,
});
http://professional-guru.com
Scope
Scopes are arranged in hierarchical structure which mimic the DOM structure of the
application.
$scope
http://professional-guru.com
Dependency Injection
Dependency Injection (DI) is asoftware design pattern that deals with how code gets hold
of its dependencies.
http://professional-guru.com
Filters
{{ uppercase_expression | uppercase}}
http://professional-guru.com