SlideShare une entreprise Scribd logo
1  sur  41
AngularJS
A better way to create web apps
Agenda
O Introduction to AngularJS
O Some concepts used in AngularJS
O Testing application built with Angular
O Productivity and debugging tools
O Code organization for large projects
O Code demo as we go on
Why AngularJS
O HTML was created to transmit markup
data on web. E.g. <b> tags for making text
bold etc.
O JavaScript added for interactivity.
O And then comes AJAX and rich web
apps.
O And things get messed up by adding
listeners after getting ids, callbacks and
series of callbacks.
What can AngularJS do
O Less boilerplate code, faster development
with less code and thus less tests and
bugs.
O Clean separation of DOM
manipulation, business logic and views
make things easier to test.
O Declarative UI design means designers
can focus on their work without even
knowing JavaScript.
O Support for cool stuff like promises.
Angular components
This is the real stuff
Angular App
Modules
Models
Controllers
Templates (and Views)
Directives
Services
Filters
Routes
Module
O Angular apps have nothing like a main
method
O Directive ng-app used to bootstrap the
module
O E.g. <html ng-app=“someModule”>
O A module can contain several other
components
O var module =
angular.module(„someModule‟, [])
O Second argument is an array of other
modules which are requisites for the current
module.
Models
O In Angular, model is any data that is
reachable as property of $scope object
O Can also create models inside templates
using the ng-model directive e.g. <input
type=“email” ng-model=“user.email”>
O Can watch models for changes using
$watch(watchFn, watchAction, deepWatch)
O deepWatch is a boolean which allows to
watch attributes of the object returned by
watchFn
Controllers
O Set up the $scope
O Add behavior to $scope
O All business logic to be written in here.
O Can use the one controller per template
to create really traditional websites.
Templates
O Specify how things should show up and
what happens on particular user actions.
O Angular templates are not the view in
MVC. Compiled angular templates are the
views.
O Declaratively create the UI using
directives.
Directives
O One of the most important part of Angular
O Allows you to extend HTML to define
custom tags, attributes and classes for UI
components.
Jquery UI Angular Directives
<div id=“tabs”>
<ul>
<li><a href=“#tabs-1”> Tab1</a></li>
<li><a href=“#tabs-2”> Tab2</a></li>
</ul>
<div id=“#tabs-1>Content</div>
<div id=“#tabs-2>Content2</div>
</div>
<script>
$(function() {
$(„#tabs”).tabs();
});
</script>
<tab-set>
<tab title=“Tab1”>Content</tab>
<tab title=“Tab2”>Content2</tab>
</tab-set>
Now what if you need tabs on
10 pages in your whole
application ?
Services
O Stuff required at various places e.g. by
various controllers.
O E.g. a http request to get list of blog posts
in a blogging application would be
required while showing all blog posts, in
the admin edit/publish view etc.
O Three different ways to create services
i.e. services, factory and provider.
Filters
O Filters are transformations applies to
objects
O Not important to logic used to process
models e.g. currency sign (like $)
O E.g. lowerCase, sort etc.
O Built-in filters like json
O Custom filters can be defined with
app.filter(„filterName‟, function (obj)
{})
Routes
O Used to map templates and associated
controller to URLs.
O Supports HTML5 mode where you get
history support.
O That‟s it !
Form Validation
O Provides special support for two
properties $valid, $invalid.
O Can use them like <button ng-
disabled=“!formName.$valid”> to disable a
form until its all elements are correct.
O polyfills for things like „required‟ on non-
HTML browsers
Server-side communication
O $http wraps the XHR to provide
asynchronous requests.
O $resource for interacting with RESTful
resources. (provided as a separate
module in angular-resource.js)
O $http requests support promises (talk
about this later)
Secrets of all the magic in
Angular
What actually happens
O Template loads with all the angular directives
O Angular script loads and after template
loading finishes, it looks for ng-app to find
application boundaries.
O Compile phase – Angular walks the DOM to
identify registered directive and transforms
them.
O Link Phase – This runs a link function for
each directive which typically creates listeners
on DOM or model and keeps view and model
in sync .
$scope
O $scope allows binding and
communication between controller and
templates.
O All the model objects are stored on it.
O Makes sense not to store everything on it
as it would degrade performance.
Data binding
O Binding two sources together and keep
then updated of changes.
O Angular supports two-way data binding.
O Change in models get reflected
everywhere in view.
O Changes in view gets reflected in the
model.
Dependency Injection
O Follows Law of Demeter or principle of
least knowledge.
O Instead of creating things, just ask for
what is required.
O E.g. to create a Car you need an engine
so instead of calling an engine Factory in
the constructor, pass an engine as
parameter.
O Makes things easier to test (e.g. mock
$http), less code and easier to change
later.
Promises
O A promise is an interface that deals with
objects that are returned or get filled in at
a future point in time.
O Current approach with callbacks has
problems of indentation while chaining
multiple calls, losing errors reported
between callbacks unless manually
handled and doing real stuff in innermost
callback.
Promises
O In angular a promise gives with a then
function which takes two functions as a
parameter for promises getting resolved
(success) or rejected (failure)
O A promise can be –
O chained so you do not get code with callbacks
inside callbacks that flows out of the screen.
O errors propagate and can be handled at the
end.
O Assurance that previous call finishes before
next call.
Testing apps built with
Angular
Why Test ?
O Things do what they are expected to do.
O Future addition of code does not affect
previous features.
O Reduces effort in the long run but maybe
pain to write initially.
Unit tests in Angular
O Test stuffs like controllers, filters, services
and directives.
O Separation of DOM code makes testing
easier and possible.
O Using Jasmine like syntax and Jasmine
Spy instead of real browser.
Karma
O Karma is a test runner in JavaScript
O Test on real devices
O Control the whole workflow from
command line.
O Lightening fast !!
Scenario tests
O End to end tests involving complete
feature.
O E.g. first page of a blog should display N
blog posts.
O Done using Karma in Angular
Tools for productivity
Yeoman m/
O Lightning-fast scaffolding
O Built-in preview server
O Integrated package management
O An awesome build process
O Unit testing using PhantomJS
Batarang
O Chrome extension for angular
O Provides performance metrics, see
scopes and values of properties in them.
O Can change the values and see the
change in realtime.
IDE plugins
O Webstorm plugin is awesome.
O Sublime text angular plugin.
Angular Future
O Animations
O Breaking down into components
O alternative syntax work without the
$scope thing but not really useful.
O Much More…
Best practices
Because you can still write yucky code in Angular
No DOM manipulation in
controller
Things which are to be used
in multiple controllers ?
Use services
To wrap third party plugins
like JQuery date-picker, use
directives
Write tests.
This one is for me 
Use promises, they are
awesome.
Code organization
O Angular seed style
O Yeoman Style
O Any style you prefer
Learn more about it
O Angular Channel on Youtube
O http://www.yearofmoo.com
O egghead.io
O Stack Overflow
O Quora 

Contenu connexe

Tendances

Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginnersImran Qasim
 
Angular material tutorial
Angular material tutorialAngular material tutorial
Angular material tutorialHarikaReddy115
 
Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in AngularAlexe Bogdan
 
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...Edureka!
 
Angular components
Angular componentsAngular components
Angular componentsSultan Ahmed
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS OrisysIndia
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceOleksii Prohonnyi
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questionsGoa App
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionOleksii Prohonnyi
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIEric Wise
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.jsDev_Events
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJSGregor Woiwode
 

Tendances (20)

Angular js
Angular jsAngular js
Angular js
 
Angular 5 presentation for beginners
Angular 5 presentation for beginnersAngular 5 presentation for beginners
Angular 5 presentation for beginners
 
Angular 9
Angular 9 Angular 9
Angular 9
 
Angular material tutorial
Angular material tutorialAngular material tutorial
Angular material tutorial
 
Angular 9 New features
Angular 9 New featuresAngular 9 New features
Angular 9 New features
 
Dependency Injection pattern in Angular
Dependency Injection pattern in AngularDependency Injection pattern in Angular
Dependency Injection pattern in Angular
 
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
Angular Routing Tutorial | AngularJS vs Angular Router | Angular Training | E...
 
Angular components
Angular componentsAngular components
Angular components
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Dive into Angular, part 1: Introduction
Dive into Angular, part 1: IntroductionDive into Angular, part 1: Introduction
Dive into Angular, part 1: Introduction
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Adding User Management to Node.js
Adding User Management to Node.jsAdding User Management to Node.js
Adding User Management to Node.js
 
Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Angular Seminar-js
Angular Seminar-jsAngular Seminar-js
Angular Seminar-js
 

En vedette

AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introductionTania Gonzales
 
An introduction to AngularJS
An introduction to AngularJSAn introduction to AngularJS
An introduction to AngularJSYogesh singh
 
AngularJS Introduction
AngularJS IntroductionAngularJS Introduction
AngularJS IntroductionCarlos Morales
 
Hands On Intro to Node.js
Hands On Intro to Node.jsHands On Intro to Node.js
Hands On Intro to Node.jsChris Cowan
 
JS Frameworks - Angular Vs Backbone
JS Frameworks - Angular Vs BackboneJS Frameworks - Angular Vs Backbone
JS Frameworks - Angular Vs BackboneGourav Jain, MCTS®
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsRan Mizrahi
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with Angular 2FITC
 

En vedette (8)

AngularJS introduction
AngularJS introductionAngularJS introduction
AngularJS introduction
 
An introduction to AngularJS
An introduction to AngularJSAn introduction to AngularJS
An introduction to AngularJS
 
AngularJS Introduction
AngularJS IntroductionAngularJS Introduction
AngularJS Introduction
 
Hands On Intro to Node.js
Hands On Intro to Node.jsHands On Intro to Node.js
Hands On Intro to Node.js
 
JS Frameworks - Angular Vs Backbone
JS Frameworks - Angular Vs BackboneJS Frameworks - Angular Vs Backbone
JS Frameworks - Angular Vs Backbone
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Getting Started with Angular 2
Getting Started with Angular 2Getting Started with Angular 2
Getting Started with Angular 2
 

Similaire à AngularJS Introduction (Talk given on Aug 5 2013)

Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014Sarah Hudson
 
Angularjs on line training
Angularjs on line trainingAngularjs on line training
Angularjs on line trainingJahan Murugassan
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project ReportKodexhub
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to AngularjsGaurav Agrawal
 
Getting Started with AngularJS
Getting Started with AngularJSGetting Started with AngularJS
Getting Started with AngularJSEdureka!
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresherRavi Bhadauria
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day trainingTroy Miles
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaphp2ranjan
 
Getting Started With AngularJS
Getting Started With AngularJSGetting Started With AngularJS
Getting Started With AngularJSEdureka!
 
AngularJS for Beginners
AngularJS for BeginnersAngularJS for Beginners
AngularJS for BeginnersEdureka!
 
What are the key distinctions between Angular and AngularJS?
What are the key distinctions between Angular and AngularJS?What are the key distinctions between Angular and AngularJS?
What are the key distinctions between Angular and AngularJS?Albiorix Technology
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development GuideNitin Giri
 
A Big Picture Of AngularJS
A Big Picture Of AngularJSA Big Picture Of AngularJS
A Big Picture Of AngularJSNitin Pandit
 
Angular js getting started
Angular js getting startedAngular js getting started
Angular js getting startedHemant Mali
 

Similaire à AngularJS Introduction (Talk given on Aug 5 2013) (20)

Angular js 1.3 presentation for fed nov 2014
Angular js 1.3 presentation for fed   nov 2014Angular js 1.3 presentation for fed   nov 2014
Angular js 1.3 presentation for fed nov 2014
 
AngularJS in practice
AngularJS in practiceAngularJS in practice
AngularJS in practice
 
Angularjs on line training
Angularjs on line trainingAngularjs on line training
Angularjs on line training
 
Angular Project Report
 Angular Project Report Angular Project Report
Angular Project Report
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Getting Started with AngularJS
Getting Started with AngularJSGetting Started with AngularJS
Getting Started with AngularJS
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 
Angular js interview question answer for fresher
Angular js interview question answer for fresherAngular js interview question answer for fresher
Angular js interview question answer for fresher
 
Angular Basics.pptx
Angular Basics.pptxAngular Basics.pptx
Angular Basics.pptx
 
Intro to AngularJs
Intro to AngularJsIntro to AngularJs
Intro to AngularJs
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day training
 
Angular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad indiaAngular 6 Training with project in hyderabad india
Angular 6 Training with project in hyderabad india
 
Getting Started With AngularJS
Getting Started With AngularJSGetting Started With AngularJS
Getting Started With AngularJS
 
AngularJS for Beginners
AngularJS for BeginnersAngularJS for Beginners
AngularJS for Beginners
 
What are the key distinctions between Angular and AngularJS?
What are the key distinctions between Angular and AngularJS?What are the key distinctions between Angular and AngularJS?
What are the key distinctions between Angular and AngularJS?
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
A Big Picture Of AngularJS
A Big Picture Of AngularJSA Big Picture Of AngularJS
A Big Picture Of AngularJS
 
Angular js getting started
Angular js getting startedAngular js getting started
Angular js getting started
 
AngularJS
AngularJSAngularJS
AngularJS
 
AngularJS
AngularJS AngularJS
AngularJS
 

Dernier

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 

Dernier (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 

AngularJS Introduction (Talk given on Aug 5 2013)

  • 1. AngularJS A better way to create web apps
  • 2. Agenda O Introduction to AngularJS O Some concepts used in AngularJS O Testing application built with Angular O Productivity and debugging tools O Code organization for large projects O Code demo as we go on
  • 3. Why AngularJS O HTML was created to transmit markup data on web. E.g. <b> tags for making text bold etc. O JavaScript added for interactivity. O And then comes AJAX and rich web apps. O And things get messed up by adding listeners after getting ids, callbacks and series of callbacks.
  • 4. What can AngularJS do O Less boilerplate code, faster development with less code and thus less tests and bugs. O Clean separation of DOM manipulation, business logic and views make things easier to test. O Declarative UI design means designers can focus on their work without even knowing JavaScript. O Support for cool stuff like promises.
  • 5. Angular components This is the real stuff
  • 6. Angular App Modules Models Controllers Templates (and Views) Directives Services Filters Routes
  • 7. Module O Angular apps have nothing like a main method O Directive ng-app used to bootstrap the module O E.g. <html ng-app=“someModule”> O A module can contain several other components O var module = angular.module(„someModule‟, []) O Second argument is an array of other modules which are requisites for the current module.
  • 8. Models O In Angular, model is any data that is reachable as property of $scope object O Can also create models inside templates using the ng-model directive e.g. <input type=“email” ng-model=“user.email”> O Can watch models for changes using $watch(watchFn, watchAction, deepWatch) O deepWatch is a boolean which allows to watch attributes of the object returned by watchFn
  • 9. Controllers O Set up the $scope O Add behavior to $scope O All business logic to be written in here. O Can use the one controller per template to create really traditional websites.
  • 10. Templates O Specify how things should show up and what happens on particular user actions. O Angular templates are not the view in MVC. Compiled angular templates are the views. O Declaratively create the UI using directives.
  • 11. Directives O One of the most important part of Angular O Allows you to extend HTML to define custom tags, attributes and classes for UI components. Jquery UI Angular Directives <div id=“tabs”> <ul> <li><a href=“#tabs-1”> Tab1</a></li> <li><a href=“#tabs-2”> Tab2</a></li> </ul> <div id=“#tabs-1>Content</div> <div id=“#tabs-2>Content2</div> </div> <script> $(function() { $(„#tabs”).tabs(); }); </script> <tab-set> <tab title=“Tab1”>Content</tab> <tab title=“Tab2”>Content2</tab> </tab-set> Now what if you need tabs on 10 pages in your whole application ?
  • 12. Services O Stuff required at various places e.g. by various controllers. O E.g. a http request to get list of blog posts in a blogging application would be required while showing all blog posts, in the admin edit/publish view etc. O Three different ways to create services i.e. services, factory and provider.
  • 13. Filters O Filters are transformations applies to objects O Not important to logic used to process models e.g. currency sign (like $) O E.g. lowerCase, sort etc. O Built-in filters like json O Custom filters can be defined with app.filter(„filterName‟, function (obj) {})
  • 14. Routes O Used to map templates and associated controller to URLs. O Supports HTML5 mode where you get history support. O That‟s it !
  • 15. Form Validation O Provides special support for two properties $valid, $invalid. O Can use them like <button ng- disabled=“!formName.$valid”> to disable a form until its all elements are correct. O polyfills for things like „required‟ on non- HTML browsers
  • 16. Server-side communication O $http wraps the XHR to provide asynchronous requests. O $resource for interacting with RESTful resources. (provided as a separate module in angular-resource.js) O $http requests support promises (talk about this later)
  • 17. Secrets of all the magic in Angular
  • 18. What actually happens O Template loads with all the angular directives O Angular script loads and after template loading finishes, it looks for ng-app to find application boundaries. O Compile phase – Angular walks the DOM to identify registered directive and transforms them. O Link Phase – This runs a link function for each directive which typically creates listeners on DOM or model and keeps view and model in sync .
  • 19. $scope O $scope allows binding and communication between controller and templates. O All the model objects are stored on it. O Makes sense not to store everything on it as it would degrade performance.
  • 20. Data binding O Binding two sources together and keep then updated of changes. O Angular supports two-way data binding. O Change in models get reflected everywhere in view. O Changes in view gets reflected in the model.
  • 21. Dependency Injection O Follows Law of Demeter or principle of least knowledge. O Instead of creating things, just ask for what is required. O E.g. to create a Car you need an engine so instead of calling an engine Factory in the constructor, pass an engine as parameter. O Makes things easier to test (e.g. mock $http), less code and easier to change later.
  • 22. Promises O A promise is an interface that deals with objects that are returned or get filled in at a future point in time. O Current approach with callbacks has problems of indentation while chaining multiple calls, losing errors reported between callbacks unless manually handled and doing real stuff in innermost callback.
  • 23. Promises O In angular a promise gives with a then function which takes two functions as a parameter for promises getting resolved (success) or rejected (failure) O A promise can be – O chained so you do not get code with callbacks inside callbacks that flows out of the screen. O errors propagate and can be handled at the end. O Assurance that previous call finishes before next call.
  • 24. Testing apps built with Angular
  • 25. Why Test ? O Things do what they are expected to do. O Future addition of code does not affect previous features. O Reduces effort in the long run but maybe pain to write initially.
  • 26. Unit tests in Angular O Test stuffs like controllers, filters, services and directives. O Separation of DOM code makes testing easier and possible. O Using Jasmine like syntax and Jasmine Spy instead of real browser.
  • 27. Karma O Karma is a test runner in JavaScript O Test on real devices O Control the whole workflow from command line. O Lightening fast !!
  • 28. Scenario tests O End to end tests involving complete feature. O E.g. first page of a blog should display N blog posts. O Done using Karma in Angular
  • 30. Yeoman m/ O Lightning-fast scaffolding O Built-in preview server O Integrated package management O An awesome build process O Unit testing using PhantomJS
  • 31. Batarang O Chrome extension for angular O Provides performance metrics, see scopes and values of properties in them. O Can change the values and see the change in realtime.
  • 32. IDE plugins O Webstorm plugin is awesome. O Sublime text angular plugin.
  • 33. Angular Future O Animations O Breaking down into components O alternative syntax work without the $scope thing but not really useful. O Much More…
  • 34. Best practices Because you can still write yucky code in Angular
  • 35. No DOM manipulation in controller
  • 36. Things which are to be used in multiple controllers ? Use services
  • 37. To wrap third party plugins like JQuery date-picker, use directives
  • 38. Write tests. This one is for me 
  • 39. Use promises, they are awesome.
  • 40. Code organization O Angular seed style O Yeoman Style O Any style you prefer
  • 41. Learn more about it O Angular Channel on Youtube O http://www.yearofmoo.com O egghead.io O Stack Overflow O Quora 

Notes de l'éditeur

  1.  Angular comes with several filters, like currency, which we’ve seen:{{12.9 | currency}}This bit of code will display the following:$12.90We put this declaration in the view (rather than in the controller or model) because thedollar sign in front of the number is only important to humans, and not to the logic weuse to process the number.varhomeModule = angular.module(&apos;HomeModule&apos;, []);homeModule.filter(&apos;titleCase&apos;, function() {vartitleCaseFilter = function(input) {varwords = input.split(&apos; &apos;);for (vari = 0; i &lt; words.length; i++) {words[i] = words[i].charAt(0).toUpperCase() + words[i].slice(1);}return words.join(&apos; &apos;);};return titleCaseFilter;});
  2. Script loadsAngular loads and looks for the ng-app directive to find the application boundaries.Compile phaseIn this phase, Angular walks the DOM to identify all the registered directives in thetemplate. For each directive, it then transforms the DOM based on the directive’srules (template, replace, transclude, and so on), and calls the compile functionif it exists. The result is a compiled template function, which will invoke the linkfunctions collected from all of the directives.Link phaseTo make the view dynamic, Angular then runs a link function for each directive.The link functions typically creates listeners on the DOM or the model. Theselisteners keep the view and the model in sync at all times. …. functions deal with transforming the template itself, and link functions deal with makinga dynamic connection between model and view. It is in this second phase that scopesare attached to the compiled link functions, and the directive becomes live throughdata binding. These two phases are separate for performance reasons. Compile functions execute onlyonce in the compile phase, whereas link functions are executed many times, once foreach instance of the directive. For example, let’s say you use ng-repeat over your directive.You don’t want to call compile, which causes a DOM-walk on each ngrepeatiteration. Instead, you want to compile once, then link.