SlideShare a Scribd company logo
HTML enhanced for web apps!
Presented by - Murtaza Haveliwala
About Me
• Software/UI Developer @ Synerzip Softech
• 5+ years of development experience
o Java stack – Swing, Eclipse, J2EE, Tapestry etc.
o JavaScript stack – Jquery, YUI, XPCOM etc.
• Current interests – NodeJs, AngularJs & Polymer
• Contact:
o murtaza.sh@gmail.com
o LinkedIn: Murtaza Haveliwala
o facebook.com/murtaza.haveliwala
Agenda
• Why AngularJs?
• What is AngularJs?
• Getting started
o Anatomy of an Angular app
o MVC
o Data-binding
o Bindings, expressions, filters
o Directives
o Services
o Dependency Injections
• Demo
• Form Validation
• Custom Directives
• Best practices
• Q&A
Why AngularJs?
• Attempt to make static HTML  dynamic, easier and fun
• Flexible & extensible
• Well organized - highly modular
• Write less code
• Focus on testing – Jasmine, Karma, Protractor etc.
• Versatile - works well with other libraries
What is AngularJs?
• Framework
• Free & open source (MIT License)
• Current version – 1.2.16
• Vibrant & growing community – Good documentation, tons of articles & videos
available
o Project home page – angularjs.org
o Guide – docs.angularjs.org/guide
o API reference - docs.angularjs.org/api
• Browser support - IE8+*, Firefox , Chrome & Safari
• Whose using it? YouTube on PS3, Plunker, DoubleClick and many more
(builtwith.angularjs.org)
What is AngularJs?...
What is AngularJs?...
Other Modules
Services
angular-route.js
$resource$resource
Directives
ng-viewng-view
Services
angular-route.js
$resource$resource
Directives
ng-viewng-view
Third-party Modules
Services
$resource$resource
Directives
ng-viewng-view
Services
angular-ui.js
$resource$resource
Directives
ng-ving-grid
jqLiteAngular Core
Services Directives Filters
$injector $injector$scope$injector ng-modelng-repeat $inJectorcurrencydate
Getting Started..
Anatomy of an Angular App
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<script src="js/libs/angular.js"></script>
</head>
<body ng-app>
<div>
<input type="text" ng-model="myString" />
{{ myString }}
</div>
</body>
</html>
Basic
Anatomy of an Angular App
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<script src="js/libs/angular.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app>
<div ng-controller=“MyController”>
<input type="text" ng-model="myString" />
{{ myString }}
</div>
</body>
</html>
Better
// app.js
function MyController($scope) {
$scope.myString = „hello world!‟;
}
Anatomy of an Angular App
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<script src="js/libs/angular.js"></script>
<script src="js/app.js"></script>
</head>
<body ng-app=“myApp”>
<div ng-controller=“MyController”>
<input type="text" ng-model="myString" />
{{ myString }}
</div>
</body>
</html>
Even better
// app.js
var myApp = angular.module('myApp', []);
myApp.controller(„MyController‟, [„$scope‟, function($scope) {
$scope.myString = „hello world!‟;
}]);
MVC
Model View ControllerTheory:
Plain Object HTML Plain FunctionAngular World:
$scope <... ng-controller=“MyCtrl”> function MyCtrl ($scope)Syntax:
Think of:
Data-binding
• View is an instant projection of the model
• Eliminates need of event binding and handling
• Achieved through
o ng-model directive,
o $scope object
o {{ }} bindings,
o $watch method
o etc..
automatic
Bindings, Expressions
• Binding – {{ <expression> | filter | orderBy }}
o To be used in Views/HTML.
• Expressions –
o JavaScript *like* code-snippets – {{ 1 + 2 }}, {{ ‘hello World!’ }}
o Evaluated against a ‘$scope’ object – {{ a + b }}, {{ user.name }}, {{ items[index] }}, {{
doSomething() }}
o *Cannot* use conditionals, loops & exceptions
• Filters – Data formatters
o lowercase, currency, date & any custom-filters
• orderBy – Sorts filtered result-set
Directives
Used to teach HTML new tricks
ng-app
ng-repeat ng-class
ng-disabled ng-show ng-click
ng-model
ng-checked
ng-controller
ng-dblclick
ng-href
ng-submit
ng-transclude ng-change
Many more!
ng-if
ng-init
ng-form
Directives
• Used to
o Create new tags or attributes – tabs, accordions, ng-repeat, ng-app, ng-disabled etc.
o Extend other HTML attributes with more capabilities – required, type, input etc.
o Abstract repetitive markups via ng-include, ng-transclude and ng-view
• Can be expressed as a
o Tag – <my-directive></my-directive>
o Attribute – ng-app, ng-controller, ng-model, ng-disabled
o Class – one of the className in an element’s ‘class’ attribute
o (HTML) Comment – <!-- my-directive -->
• No magic, implemented purely using JS and HTML 
Mini
Demo
Basic Anatomy
Data-binding, Directives & Filters
Services
• Reusable business logic, independent of views
• Can be used by controllers and other services/components
• Defined like this –
• Many flavors – factories , services & providers
o Mainly differ in their creational pattern
angular.module('myModule', []).
factory('greeter', function(someDependency) {
// do some initialization here, any internal methods,
// if required
return {
myMethod: function(text) {
return text.toUpperCase();
}
};
});
Dependency Injections (DI)
• Creates and wires objects/functions
• Freedom from creating and managing services, internal
dependencies
o No need of doing ‘new’ for components
o No more inter-dependency management
• Handled by ‘Injector’ sub-system
• All services, modules registered via Ids – $scope, $http, greeter
etc.
o Modules assist in registering their own components
o Crucial in writing unit and end-to-end tests
• Angular sub-system != requireJS/ AMD.js
Demo
Simple TODO App
Single Page App - TODO App
Ajax Serviced TODO App
Form Validation
• Make use of these validation directives -
o required, type, ng-minlength, ng-maxlength, ng-pattern
o Your own custom directive
• Start by - adding ‘name’ attribute to ‘form’ and ‘form elements’
• Angular attaches these properties to form and form elements
• Accessed as
o Form: <form name>.<property>
o Individual form element: <form name>.<element name>.<property>
• Applies these styling classes –
o .ng-valid, .ng-invalid, .ng-pristine, .ng-dirty
o .ng-invalid-required, .ng-valid-max-length, etc.
• Use ‘novalidate’ attribute to stop HTML5 auto validation
Custom Directives
angular.module('myModule', []).
directive('myDirective', function() {
return {
restrict: 'A', // < E | A | C | M >
template: '<div>...some more markup...</div>',
templateUrl: 'my-directive-template.html',
replace: false,
transclude: true, // < false | true >
scope: { // < true | false | {} >
'localFoo': '@foo' // < @ | @attribute>
'localBar': '=info' // < = | =attribute | =? attribute>
'myProp': '&expression' // < & | &attribute >
},
controller: function($scope, myDepedencies, ...) {...},
require: 'myOtherDirective' // prefix - < (no prefix) | ? | ^ | ?^ >
link: function postLink(scope, iElement, iAttrs, otherController, ... ) { ... }
};
});
<my-directive attribute=“some attribute” ..>
<span>text</span>
<div ng-transclude />
</my-directive>
Best Practices
• In HTML templates/views,
o Use Directives for abstracting common markups, extensions
o Do not use complex expressions in bindings. Move them to Controllers
o Optimize use of bindings. Lesser, the faster your application gets
• In Controllers,
o Keep them light. Use Services to offload functionality
o No DOM manipulations! Delegate them to directives
• In Directives,
o Prefer using directives as tag names or attributes over classes and comments
o Do not use ‘ng-’ prefix for your directives
o Create isolate scopes to avoid accidental overrides of properties
o Notify Angular about direct changes on DOM, via $scope.$apply
• Create modules to group controllers, services, directives etc.
• Test (unit & E2E) each component – Services, Controllers, Directives etc.
Best Practices..
• Use $inject pattern for defining components.
o Avoids breakages when minifying
• Do not create $ and $$ prefixed APIs
o Could lead to collisions
• Prefer ‘data-’ prefix when using directives
Questions?
References
• Articles
o AngularJS official guide
o Use AngularJS to power your application
o Why does AngularJS rock?
o Rapid prototyping with AngularJs
o AngularJs Form Validation
• Videos
o Official YouTube channel
o AngularJs Fundamentals in 60-ish minutes
o Writing Directives
o Introduction to AngularJs Unit Testing
o End to End testing of AngularJs apps with Protractor
Thank you!

More Related Content

What's hot (20)

AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
Ravi Mone
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
dizabl
 
AngularJS custom directive
AngularJS custom directiveAngularJS custom directive
AngularJS custom directive
Nascenia IT
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
Elad Hirsch
 
Custom AngularJS Directives
Custom AngularJS DirectivesCustom AngularJS Directives
Custom AngularJS Directives
yprodev
 
Angular JS tutorial
Angular JS tutorialAngular JS tutorial
Angular JS tutorial
cncwebworld
 
Angular Directives
Angular DirectivesAngular Directives
Angular Directives
iFour Technolab Pvt. Ltd.
 
Angular js 1.3 basic tutorial
Angular js 1.3 basic tutorialAngular js 1.3 basic tutorial
Angular js 1.3 basic tutorial
Al-Mutaz Bellah Salahat
 
Angular js
Angular jsAngular js
Angular js
Larry Ball
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
Sagar Acharya
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
Betclic Everest Group Tech Team
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 
Angular js 1.0-fundamentals
Angular js 1.0-fundamentalsAngular js 1.0-fundamentals
Angular js 1.0-fundamentals
Venkatesh Narayanan
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
Akshay Mathur
 
Angular js
Angular jsAngular js
Angular js
Dinusha Nandika
 
Introduction to single page application with angular js
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular js
Mindfire Solutions
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
Sathish VJ
 
Angular js
Angular jsAngular js
Angular js
Manav Prasad
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
Ravi Mone
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
dizabl
 
AngularJS custom directive
AngularJS custom directiveAngularJS custom directive
AngularJS custom directive
Nascenia IT
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
Elad Hirsch
 
Custom AngularJS Directives
Custom AngularJS DirectivesCustom AngularJS Directives
Custom AngularJS Directives
yprodev
 
Angular JS tutorial
Angular JS tutorialAngular JS tutorial
Angular JS tutorial
cncwebworld
 
Angular JS - Introduction
Angular JS - IntroductionAngular JS - Introduction
Angular JS - Introduction
Sagar Acharya
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
Sakthi Bro
 
Getting Started with Angular JS
Getting Started with Angular JSGetting Started with Angular JS
Getting Started with Angular JS
Akshay Mathur
 
Introduction to single page application with angular js
Introduction to single page application with angular jsIntroduction to single page application with angular js
Introduction to single page application with angular js
Mindfire Solutions
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
Aayush Shrestha
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
Sathish VJ
 

Viewers also liked (19)

Building Modern Web Apps with AngularJS
Building Modern Web Apps with AngularJSBuilding Modern Web Apps with AngularJS
Building Modern Web Apps with AngularJS
Raveen Perera
 
Angular 1.5 Components
Angular 1.5 ComponentsAngular 1.5 Components
Angular 1.5 Components
José Barbosa
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
M R Rony
 
Componentes en angularjs 1.5
Componentes en angularjs 1.5Componentes en angularjs 1.5
Componentes en angularjs 1.5
Hugo Biarge
 
FrontEnd platform based on AngularJS
FrontEnd platform based on AngularJSFrontEnd platform based on AngularJS
FrontEnd platform based on AngularJS
Egor Miasnikov
 
Dependency injection
Dependency injectionDependency injection
Dependency injection
Mindfire Solutions
 
Intro to AngularJS
Intro to AngularJS Intro to AngularJS
Intro to AngularJS
Sparkhound Inc.
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01
Arunangsu Sahu
 
AngularJS vs jQuery
AngularJS vs jQueryAngularJS vs jQuery
AngularJS vs jQuery
PayPal
 
Dive into AngularJS and directives
Dive into AngularJS and directivesDive into AngularJS and directives
Dive into AngularJS and directives
Tricode (part of Dept)
 
AngularJs
AngularJsAngularJs
AngularJs
Abdhesh Kumar
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 
Comment réussir son projet en Angular 1.5 ?
Comment réussir son projet en Angular 1.5 ?Comment réussir son projet en Angular 1.5 ?
Comment réussir son projet en Angular 1.5 ?
Maxime Bernard
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
Sumanth krishna
 
Creating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsCreating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web Components
Rachael L Moore
 
AngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW FrameworkAngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW Framework
Edureka!
 
AngularJS
AngularJSAngularJS
AngularJS
Yogesh L
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Building Modern Web Apps with AngularJS
Building Modern Web Apps with AngularJSBuilding Modern Web Apps with AngularJS
Building Modern Web Apps with AngularJS
Raveen Perera
 
Angular 1.5 Components
Angular 1.5 ComponentsAngular 1.5 Components
Angular 1.5 Components
José Barbosa
 
Single Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJSSingle Page Application (SPA) using AngularJS
Single Page Application (SPA) using AngularJS
M R Rony
 
Componentes en angularjs 1.5
Componentes en angularjs 1.5Componentes en angularjs 1.5
Componentes en angularjs 1.5
Hugo Biarge
 
FrontEnd platform based on AngularJS
FrontEnd platform based on AngularJSFrontEnd platform based on AngularJS
FrontEnd platform based on AngularJS
Egor Miasnikov
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01
Arunangsu Sahu
 
AngularJS vs jQuery
AngularJS vs jQueryAngularJS vs jQuery
AngularJS vs jQuery
PayPal
 
Angular js presentation at Datacom
Angular js presentation at DatacomAngular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 
Comment réussir son projet en Angular 1.5 ?
Comment réussir son projet en Angular 1.5 ?Comment réussir son projet en Angular 1.5 ?
Comment réussir son projet en Angular 1.5 ?
Maxime Bernard
 
Scope demystified - AngularJS
Scope demystified - AngularJSScope demystified - AngularJS
Scope demystified - AngularJS
Sumanth krishna
 
Creating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web ComponentsCreating GUI Component APIs in Angular and Web Components
Creating GUI Component APIs in Angular and Web Components
Rachael L Moore
 
AngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW FrameworkAngularJS : Superheroic JavaScript MVW Framework
AngularJS : Superheroic JavaScript MVW Framework
Edureka!
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
Gary Arora
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
Eyal Vardi
 
Ad

Similar to Introduction to AngularJs (20)

Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
Adam Moore
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
Ravindra K
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
Intro to AngularJs
Intro to AngularJsIntro to AngularJs
Intro to AngularJs
SolTech, Inc.
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
Filip Janevski
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
Ran Wahle
 
AngularJS.part1
AngularJS.part1AngularJS.part1
AngularJS.part1
Andrey Kolodnitsky
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
Manish Shekhawat
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
Appfinz Technologies
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
SC5.io
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
Gianluca Cacace
 
Everything You Need To Know About AngularJS
Everything You Need To Know About AngularJSEverything You Need To Know About AngularJS
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
AngularJS
AngularJSAngularJS
AngularJS
Hiten Pratap Singh
 
AngularJS
AngularJS AngularJS
AngularJS
NexThoughts Technologies
 
Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
Mahima Radhakrishnan
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
Eugene Fidelin
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
Keith Bloomfield
 
Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
Adam Moore
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
Ravindra K
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
Ran Wahle
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
Nitin Giri
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
Ran Wahle
 
Introduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumarIntroduction to Angularjs : kishan kumar
Introduction to Angularjs : kishan kumar
Appfinz Technologies
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Learning AngularJS  - Complete coverage of AngularJS features and conceptsLearning AngularJS  - Complete coverage of AngularJS features and concepts
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
Angular.js Primer in Aalto University
Angular.js Primer in Aalto UniversityAngular.js Primer in Aalto University
Angular.js Primer in Aalto University
SC5.io
 
Everything You Need To Know About AngularJS
Everything You Need To Know About AngularJSEverything You Need To Know About AngularJS
Everything You Need To Know About AngularJS
Sina Mirhejazi
 
ME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS FundamentalsME vs WEB - AngularJS Fundamentals
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
Ad

Recently uploaded (20)

aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjaraswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
muhammadalikhanalikh1
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan
OnePlan Solutions
 
Software Risk and Quality management.pptx
Software Risk and Quality management.pptxSoftware Risk and Quality management.pptx
Software Risk and Quality management.pptx
HassanBangash9
 
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdfBoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
Ortus Solutions, Corp
 
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdfHow a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
mary rojas
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
War Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona ToolkitWar Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona Toolkit
Sveta Smirnova
 
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROIAutoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Udit Goenka
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
SQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptxSQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptx
Ashlei5
 
Scalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple DevicesScalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple Devices
Scalefusion
 
Custom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdfCustom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdf
Digital Aptech
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdfICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
M. Luisetto Pharm.D.Spec. Pharmacology
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
Techdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk takerTechdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk taker
RajaNagendraKumar
 
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjaraswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
aswjkdwelhjdfshlfjkhewljhfljawerhwjarhwjkahrjar
muhammadalikhanalikh1
 
Design by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First DevelopmentDesign by Contract - Building Robust Software with Contract-First Development
Design by Contract - Building Robust Software with Contract-First Development
Par-Tec S.p.A.
 
Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan Delivering More with Less: AI Driven Resource Management with OnePlan
Delivering More with Less: AI Driven Resource Management with OnePlan
OnePlan Solutions
 
Software Risk and Quality management.pptx
Software Risk and Quality management.pptxSoftware Risk and Quality management.pptx
Software Risk and Quality management.pptx
HassanBangash9
 
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdfBoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
BoxLang-Dynamic-AWS-Lambda by Luis Majano.pdf
Ortus Solutions, Corp
 
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdfHow a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
How a Staff Augmentation Company IN USA Powers Flutter App Breakthroughs.pdf
mary rojas
 
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATIONAI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
AI-ASSISTED METAMORPHIC TESTING FOR DOMAIN-SPECIFIC MODELLING AND SIMULATION
miso_uam
 
War Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona ToolkitWar Story: Removing Offensive Language from Percona Toolkit
War Story: Removing Offensive Language from Percona Toolkit
Sveta Smirnova
 
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROIAutoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Autoposting.ai Sales Deck - Skyrocket your LinkedIn's ROI
Udit Goenka
 
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptxHow AI Can Improve Media Quality Testing Across Platforms (1).pptx
How AI Can Improve Media Quality Testing Across Platforms (1).pptx
kalichargn70th171
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
SQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptxSQL-COMMANDS instructionsssssssssss.pptx
SQL-COMMANDS instructionsssssssssss.pptx
Ashlei5
 
Scalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple DevicesScalefusion Remote Access for Apple Devices
Scalefusion Remote Access for Apple Devices
Scalefusion
 
Custom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdfCustom Software Development: Types, Applications and Benefits.pdf
Custom Software Development: Types, Applications and Benefits.pdf
Digital Aptech
 
Internship in South western railways on software
Internship in South western railways on softwareInternship in South western railways on software
Internship in South western railways on software
abhim5889
 
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
How John started to like TDD (instead of hating it) (ViennaJUG, June'25)
Nacho Cougil
 
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdfICDL FULL STANDARD  2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
ICDL FULL STANDARD 2025 Luisetto mauro - Academia domani- 55 HOURS LONG pdf
M. Luisetto Pharm.D.Spec. Pharmacology
 
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
Feeling Lost in the Blue? Exploring a New Path: AI Mental Health Counselling ...
officeiqai
 
UberEats clone app Development TechBuilder
UberEats clone app Development  TechBuilderUberEats clone app Development  TechBuilder
UberEats clone app Development TechBuilder
TechBuilder
 
Techdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk takerTechdebt handling with cleancode focus and as risk taker
Techdebt handling with cleancode focus and as risk taker
RajaNagendraKumar
 

Introduction to AngularJs

  • 1. HTML enhanced for web apps! Presented by - Murtaza Haveliwala
  • 2. About Me • Software/UI Developer @ Synerzip Softech • 5+ years of development experience o Java stack – Swing, Eclipse, J2EE, Tapestry etc. o JavaScript stack – Jquery, YUI, XPCOM etc. • Current interests – NodeJs, AngularJs & Polymer • Contact: o [email protected] o LinkedIn: Murtaza Haveliwala o facebook.com/murtaza.haveliwala
  • 3. Agenda • Why AngularJs? • What is AngularJs? • Getting started o Anatomy of an Angular app o MVC o Data-binding o Bindings, expressions, filters o Directives o Services o Dependency Injections • Demo • Form Validation • Custom Directives • Best practices • Q&A
  • 4. Why AngularJs? • Attempt to make static HTML  dynamic, easier and fun • Flexible & extensible • Well organized - highly modular • Write less code • Focus on testing – Jasmine, Karma, Protractor etc. • Versatile - works well with other libraries
  • 5. What is AngularJs? • Framework • Free & open source (MIT License) • Current version – 1.2.16 • Vibrant & growing community – Good documentation, tons of articles & videos available o Project home page – angularjs.org o Guide – docs.angularjs.org/guide o API reference - docs.angularjs.org/api • Browser support - IE8+*, Firefox , Chrome & Safari • Whose using it? YouTube on PS3, Plunker, DoubleClick and many more (builtwith.angularjs.org)
  • 7. What is AngularJs?... Other Modules Services angular-route.js $resource$resource Directives ng-viewng-view Services angular-route.js $resource$resource Directives ng-viewng-view Third-party Modules Services $resource$resource Directives ng-viewng-view Services angular-ui.js $resource$resource Directives ng-ving-grid jqLiteAngular Core Services Directives Filters $injector $injector$scope$injector ng-modelng-repeat $inJectorcurrencydate
  • 9. Anatomy of an Angular App <!DOCTYPE html> <html> <head> <title>My App</title> <script src="js/libs/angular.js"></script> </head> <body ng-app> <div> <input type="text" ng-model="myString" /> {{ myString }} </div> </body> </html> Basic
  • 10. Anatomy of an Angular App <!DOCTYPE html> <html> <head> <title>My App</title> <script src="js/libs/angular.js"></script> <script src="js/app.js"></script> </head> <body ng-app> <div ng-controller=“MyController”> <input type="text" ng-model="myString" /> {{ myString }} </div> </body> </html> Better // app.js function MyController($scope) { $scope.myString = „hello world!‟; }
  • 11. Anatomy of an Angular App <!DOCTYPE html> <html> <head> <title>My App</title> <script src="js/libs/angular.js"></script> <script src="js/app.js"></script> </head> <body ng-app=“myApp”> <div ng-controller=“MyController”> <input type="text" ng-model="myString" /> {{ myString }} </div> </body> </html> Even better // app.js var myApp = angular.module('myApp', []); myApp.controller(„MyController‟, [„$scope‟, function($scope) { $scope.myString = „hello world!‟; }]);
  • 12. MVC Model View ControllerTheory: Plain Object HTML Plain FunctionAngular World: $scope <... ng-controller=“MyCtrl”> function MyCtrl ($scope)Syntax: Think of:
  • 13. Data-binding • View is an instant projection of the model • Eliminates need of event binding and handling • Achieved through o ng-model directive, o $scope object o {{ }} bindings, o $watch method o etc.. automatic
  • 14. Bindings, Expressions • Binding – {{ <expression> | filter | orderBy }} o To be used in Views/HTML. • Expressions – o JavaScript *like* code-snippets – {{ 1 + 2 }}, {{ ‘hello World!’ }} o Evaluated against a ‘$scope’ object – {{ a + b }}, {{ user.name }}, {{ items[index] }}, {{ doSomething() }} o *Cannot* use conditionals, loops & exceptions • Filters – Data formatters o lowercase, currency, date & any custom-filters • orderBy – Sorts filtered result-set
  • 15. Directives Used to teach HTML new tricks ng-app ng-repeat ng-class ng-disabled ng-show ng-click ng-model ng-checked ng-controller ng-dblclick ng-href ng-submit ng-transclude ng-change Many more! ng-if ng-init ng-form
  • 16. Directives • Used to o Create new tags or attributes – tabs, accordions, ng-repeat, ng-app, ng-disabled etc. o Extend other HTML attributes with more capabilities – required, type, input etc. o Abstract repetitive markups via ng-include, ng-transclude and ng-view • Can be expressed as a o Tag – <my-directive></my-directive> o Attribute – ng-app, ng-controller, ng-model, ng-disabled o Class – one of the className in an element’s ‘class’ attribute o (HTML) Comment – <!-- my-directive --> • No magic, implemented purely using JS and HTML 
  • 18. Services • Reusable business logic, independent of views • Can be used by controllers and other services/components • Defined like this – • Many flavors – factories , services & providers o Mainly differ in their creational pattern angular.module('myModule', []). factory('greeter', function(someDependency) { // do some initialization here, any internal methods, // if required return { myMethod: function(text) { return text.toUpperCase(); } }; });
  • 19. Dependency Injections (DI) • Creates and wires objects/functions • Freedom from creating and managing services, internal dependencies o No need of doing ‘new’ for components o No more inter-dependency management • Handled by ‘Injector’ sub-system • All services, modules registered via Ids – $scope, $http, greeter etc. o Modules assist in registering their own components o Crucial in writing unit and end-to-end tests • Angular sub-system != requireJS/ AMD.js
  • 20. Demo Simple TODO App Single Page App - TODO App Ajax Serviced TODO App
  • 21. Form Validation • Make use of these validation directives - o required, type, ng-minlength, ng-maxlength, ng-pattern o Your own custom directive • Start by - adding ‘name’ attribute to ‘form’ and ‘form elements’ • Angular attaches these properties to form and form elements • Accessed as o Form: <form name>.<property> o Individual form element: <form name>.<element name>.<property> • Applies these styling classes – o .ng-valid, .ng-invalid, .ng-pristine, .ng-dirty o .ng-invalid-required, .ng-valid-max-length, etc. • Use ‘novalidate’ attribute to stop HTML5 auto validation
  • 22. Custom Directives angular.module('myModule', []). directive('myDirective', function() { return { restrict: 'A', // < E | A | C | M > template: '<div>...some more markup...</div>', templateUrl: 'my-directive-template.html', replace: false, transclude: true, // < false | true > scope: { // < true | false | {} > 'localFoo': '@foo' // < @ | @attribute> 'localBar': '=info' // < = | =attribute | =? attribute> 'myProp': '&expression' // < & | &attribute > }, controller: function($scope, myDepedencies, ...) {...}, require: 'myOtherDirective' // prefix - < (no prefix) | ? | ^ | ?^ > link: function postLink(scope, iElement, iAttrs, otherController, ... ) { ... } }; }); <my-directive attribute=“some attribute” ..> <span>text</span> <div ng-transclude /> </my-directive>
  • 23. Best Practices • In HTML templates/views, o Use Directives for abstracting common markups, extensions o Do not use complex expressions in bindings. Move them to Controllers o Optimize use of bindings. Lesser, the faster your application gets • In Controllers, o Keep them light. Use Services to offload functionality o No DOM manipulations! Delegate them to directives • In Directives, o Prefer using directives as tag names or attributes over classes and comments o Do not use ‘ng-’ prefix for your directives o Create isolate scopes to avoid accidental overrides of properties o Notify Angular about direct changes on DOM, via $scope.$apply • Create modules to group controllers, services, directives etc. • Test (unit & E2E) each component – Services, Controllers, Directives etc.
  • 24. Best Practices.. • Use $inject pattern for defining components. o Avoids breakages when minifying • Do not create $ and $$ prefixed APIs o Could lead to collisions • Prefer ‘data-’ prefix when using directives
  • 26. References • Articles o AngularJS official guide o Use AngularJS to power your application o Why does AngularJS rock? o Rapid prototyping with AngularJs o AngularJs Form Validation • Videos o Official YouTube channel o AngularJs Fundamentals in 60-ish minutes o Writing Directives o Introduction to AngularJs Unit Testing o End to End testing of AngularJs apps with Protractor