SlideShare a Scribd company logo
1 of 22
AngularJSBy
Nishikant Taksande
NetPay Merchant Services
Rewind
Basic Principles and Browser Event
$watch, $digest and $scope life cycle
$services, $filters
Module, Controllers, Directives, Scope, Filters, routes
Form Validation
<form name="form” novalidate>
<label name="email">Your email</label>
<input type="email" name="email" ng-model="email" placeholder="Email Address" />
</form>
required ng-minlength ng-maxlength
custom validation
Control Variables in Form
formName.inputFieldName.property
<div class="error” ng-show=“signup_form.name.$invalid">
...
...
</div>
Unmodified Form - formName.inputFieldName.$pristine
Modified Form - formName.inputFieldName.$dirty
Valid Form - formName.inputFieldName.$valid
Invalid Form - formName.inputFieldName.$invalid
Errors - formName.inputfieldName.$error
Form Validation…
Custom model update triggers
ng-model-options="{ updateOn: 'blur' }”
ng-model-options="{ updateOn: 'mousedown blur' }”
<input type="text" ng-model="user.name"
ng-model-options="{ updateOn: 'blur' }" />
<input type="text" ng-model="user.name" ng-model-options="{ debounce: 250 }" />
Dependency Injection…
How to get hold of dependencies?
Using ‘new’ operator
Referring global variable
Pass to it where needed
Dependency Injection…
var myModule = angular.module('myModule', []);
myModule.factory('greeter', function($window) {
return {
greet: function(text) {
$window.alert(text);
}
};
});
var injector = angular.injector(['myModule', 'ng']);
var greeter = injector.get('greeter');
Dependency Injection…
fnText = fn.toString().replace(STRIP_COMMENTS, '');
argDecl = fnText.match(FN_ARGS);
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) {
arg.replace(FN_ARG, function(all, underscore, name) {
$inject.push(name);
});
});
Named Parameter
What happens if the JavaScript code was minified?
app.controller('DemoController', ['$scope', '$http', function ($scope, $http) {}
Dependency Injection…
ng-app=“myModule”
myModule
$provide.factory(‘obA’, ‘’, …)
$injector
Instance
catch
Instance
factory
Check
cache If no cache
create new
$injector.get(a)
configure
DIRECTIVE ?
Directives
Markers on DOM element
ngBind, ngModel, ngClass
Matching directives: ng-model=“my_model”
Normalization
Directives…
<div ng-controller="Controller">
Hello <input ng-model='name'> <hr/>
</div>
ngModel
Directive Types
<my-dir></my-dir>
<span my-dir="exp"></span>
<!-- directive: my-dir exp -->
<span class="my-dir"></span>
Directives…
Embedded expression :
<a ng-href="img/{{username}}.jpg">Hello {{username}}!</a>
$watch
<svg>
<circle cx="{{cx}}"></circle>
</svg>
Error: Invalid value for attribute cx="{{cx}}"
<svg>
<circle ng-attr-cx="{{cx}}"></circle>
</svg>
Directives…
Creating directive – example 1
Directive of Directive can be composed.
Break view into separate HTML using templateUrl
Creating directive – example 2
templateUrl: function(elem, attr){
return 'customer-'+attr.type+'.html';
}
Directives…
A E C
'AEC'
Why should I use “A” or “E”?
Directives…
Isolate scope of Directive
Directive
Controller
View
dScope: ‘=myScope’
myScope = ‘cScope’
cScope: {}
html html html
dScope
Directives…
//...
scope: {
dScope: ’=myScope'
},
//...
Creating directive – example 3
Module. Why?
• Each feature
• Each reusable Component
• Application level module
HTML Compiler
Compile
Link
Quick check
angular.copy angular.isArray
ngHide ngChange
angular.isDate
angular.toJson
ngShow
ngPaste
$http $location $log
$exceptionHandler
F u n c t i o n s
D i r e c t i v e s
S e r v i c e s
AngularJS

More Related Content

What's hot

Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Shashikant Bhongale
 
[2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿![2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿!NHN FORWARD
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScriptVitaly Baum
 
Django Girls Mbale [victor's sessions]
Django Girls Mbale [victor's sessions]Django Girls Mbale [victor's sessions]
Django Girls Mbale [victor's sessions]Victor Miclovich
 
Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Shashikant Bhongale
 
Form Validation NG
Form Validation NGForm Validation NG
Form Validation NGjoaopmaia
 
ui-router and $state
ui-router and $stateui-router and $state
ui-router and $stategarbles
 
HTML5 and Mobile
HTML5 and MobileHTML5 and Mobile
HTML5 and Mobiledoodoofish
 

What's hot (11)

Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16Angular js form validation with ngmessages shashi-19-7-16
Angular js form validation with ngmessages shashi-19-7-16
 
Mini-Training: AngularJS
Mini-Training: AngularJSMini-Training: AngularJS
Mini-Training: AngularJS
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
[2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿![2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿!
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
 
Django Girls Mbale [victor's sessions]
Django Girls Mbale [victor's sessions]Django Girls Mbale [victor's sessions]
Django Girls Mbale [victor's sessions]
 
Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16Angular js form validation shashi-19-7-16
Angular js form validation shashi-19-7-16
 
Form Validation NG
Form Validation NGForm Validation NG
Form Validation NG
 
ui-router and $state
ui-router and $stateui-router and $state
ui-router and $state
 
Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
 
HTML5 and Mobile
HTML5 and MobileHTML5 and Mobile
HTML5 and Mobile
 

Viewers also liked

Colour personality
Colour personalityColour personality
Colour personalityKyra Ell
 
Oem consultancy packaged solutions strategy - machine tool case history
Oem consultancy   packaged solutions strategy - machine tool case historyOem consultancy   packaged solutions strategy - machine tool case history
Oem consultancy packaged solutions strategy - machine tool case historyBrianBensonRouteco
 
Iehoshúa se caso no
Iehoshúa se caso noIehoshúa se caso no
Iehoshúa se caso noefraimllanten
 
Oem consultancy packaged solutions strategy - label maker case history
Oem consultancy   packaged solutions strategy - label maker case historyOem consultancy   packaged solutions strategy - label maker case history
Oem consultancy packaged solutions strategy - label maker case historyBrianBensonRouteco
 
Oem consultancy packaged solutions strategy - slitter case history
Oem consultancy   packaged solutions strategy - slitter case historyOem consultancy   packaged solutions strategy - slitter case history
Oem consultancy packaged solutions strategy - slitter case historyBrianBensonRouteco
 
Cacti formation-cacti-monitoring-d-infrastructure
Cacti formation-cacti-monitoring-d-infrastructureCacti formation-cacti-monitoring-d-infrastructure
Cacti formation-cacti-monitoring-d-infrastructureCERTyou Formation
 
RI Infographic - Growing Pains 11-22-14
RI Infographic - Growing Pains 11-22-14RI Infographic - Growing Pains 11-22-14
RI Infographic - Growing Pains 11-22-14Jack McGuinness
 
Arquitectura de sistemas distribuidos
Arquitectura de sistemas distribuidosArquitectura de sistemas distribuidos
Arquitectura de sistemas distribuidosAngel Morocho
 

Viewers also liked (11)

Colour personality
Colour personalityColour personality
Colour personality
 
Oem consultancy packaged solutions strategy - machine tool case history
Oem consultancy   packaged solutions strategy - machine tool case historyOem consultancy   packaged solutions strategy - machine tool case history
Oem consultancy packaged solutions strategy - machine tool case history
 
EVENT MANAGEMENT IN KOCHI
EVENT MANAGEMENT IN KOCHIEVENT MANAGEMENT IN KOCHI
EVENT MANAGEMENT IN KOCHI
 
Iehoshúa se caso no
Iehoshúa se caso noIehoshúa se caso no
Iehoshúa se caso no
 
Oem consultancy packaged solutions strategy - label maker case history
Oem consultancy   packaged solutions strategy - label maker case historyOem consultancy   packaged solutions strategy - label maker case history
Oem consultancy packaged solutions strategy - label maker case history
 
Oem consultancy packaged solutions strategy - slitter case history
Oem consultancy   packaged solutions strategy - slitter case historyOem consultancy   packaged solutions strategy - slitter case history
Oem consultancy packaged solutions strategy - slitter case history
 
Constructo-variable
Constructo-variableConstructo-variable
Constructo-variable
 
Cacti formation-cacti-monitoring-d-infrastructure
Cacti formation-cacti-monitoring-d-infrastructureCacti formation-cacti-monitoring-d-infrastructure
Cacti formation-cacti-monitoring-d-infrastructure
 
RI Infographic - Growing Pains 11-22-14
RI Infographic - Growing Pains 11-22-14RI Infographic - Growing Pains 11-22-14
RI Infographic - Growing Pains 11-22-14
 
Wedding event management
Wedding event managementWedding event management
Wedding event management
 
Arquitectura de sistemas distribuidos
Arquitectura de sistemas distribuidosArquitectura de sistemas distribuidos
Arquitectura de sistemas distribuidos
 

Similar to angular-np-3

Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsMorgan Stone
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js FundamentalsMark
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsMark
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationDan Wahlin
 
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoFuture Insights
 
Forms in AngularJS
Forms in AngularJSForms in AngularJS
Forms in AngularJSEyal Vardi
 
FreshBooks API
FreshBooks APIFreshBooks API
FreshBooks APIBoris Mann
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with StripesSamuel Santos
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web servicesMichelangelo van Dam
 
CGI::Prototype (NPW 2006)
CGI::Prototype (NPW 2006)CGI::Prototype (NPW 2006)
CGI::Prototype (NPW 2006)brian d foy
 
前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 sessionRANK LIU
 
Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Marcin Wosinek
 
BPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced WorkflowsBPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced WorkflowsAlfresco Software
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator SimplifiedFred Moyer
 

Similar to angular-np-3 (20)

Optimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page AppsOptimizing Angular Performance in Enterprise Single Page Apps
Optimizing Angular Performance in Enterprise Single Page Apps
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
Form validation and animation
Form validation and animationForm validation and animation
Form validation and animation
 
Stripes Framework
Stripes FrameworkStripes Framework
Stripes Framework
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
Angular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd MottoAngular Performance: Then, Now and the Future. Todd Motto
Angular Performance: Then, Now and the Future. Todd Motto
 
AngularJS
AngularJSAngularJS
AngularJS
 
Forms in AngularJS
Forms in AngularJSForms in AngularJS
Forms in AngularJS
 
FreshBooks API
FreshBooks APIFreshBooks API
FreshBooks API
 
Java Web Development with Stripes
Java Web Development with StripesJava Web Development with Stripes
Java Web Development with Stripes
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
CGI::Prototype (NPW 2006)
CGI::Prototype (NPW 2006)CGI::Prototype (NPW 2006)
CGI::Prototype (NPW 2006)
 
前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session前后端mvc经验 - webrebuild 2011 session
前后端mvc经验 - webrebuild 2011 session
 
Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013
 
BPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced WorkflowsBPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced Workflows
 
Data::FormValidator Simplified
Data::FormValidator SimplifiedData::FormValidator Simplified
Data::FormValidator Simplified
 

angular-np-3

Editor's Notes

  1. Best practice: http://stackoverflow.com/questions/14994391/thinking-in-angularjs-if-i-have-a-jquery-background
  2. AngularJs make properties available on $scope object, so as to set form inside DOM. That enable us to react to form in real time. Unmodified form – boolean property tells us if user has modified the form. True if user did not modify form. Modified form – This is set only and only if user has modified the form, this is set even if form validation is not set. Valid form – tell us if form is valid. Invalid form – tell us if form is invalid Above two properties are mostly useful for showing or hiding DOM element. Error – this object contain all the validation on particular form, and tell if they are valid or not. http://www.ng-newsletter.com/posts/validations.html
  3. By default on every event angular update model and trigger form validation. So what it you want to control it. The same way we can delay changes in model update that we call debounced/ non-immediate changes https://docs.angularjs.org/guide/forms http://www.ng-newsletter.com/posts/validations.html
  4. http://anandmanisankar.com/posts/angularjs-dependency-injection-demystified/ It turns out Angular just reads the function definition using toString and parses the string to extract the parameter names. fnText = fn.toString().replace(STRIP_COMMENTS, ''); argDecl = fnText.match(FN_ARGS); forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) { arg.replace(FN_ARG, function(all, underscore, name) { $inject.push(name); }); });
  5. https://docs.angularjs.org/guide/di
  6. http://www.sitepoint.com/practical-guide-angularjs-directives/ https://docs.angularjs.org/guide/directive
  7. A module for each feature A module for each reusable component (especially directives and filters) And an application level module which depends on the above modules and contains any initialization code. https://docs.angularjs.org/guide/compiler Compiler is an Angular service which traverses the DOM looking for attributes. The compilation process happens in two phases. Compile: traverse the DOM and collect all of the directives. The result is a linking function. Link: combine the directives with a scope and produce a live view. Any changes in the scope model are reflected in the view, and any user interactions with the view are reflected in the scope model. This makes the scope model the single source of truth. Some directives such as ng-repeat clone DOM elements once for each item in a collection. Having a compile and link phase improves performance since the cloned template only needs to be compiled once, and then linked once for each clone instance.