SlideShare uma empresa Scribd logo
1 de 62
AngularJS
Fundamentals
Aviran Cohen
Hello!
I am Aviran Cohen
Full-stack Developer
7 years experience in web development
blog.avirancohen.com
facebook.com/MEvsWEB
What we’ll cover
1.A brief history of web development
2.Introduction
3.Architecture
4.Getting Started
5.Directives
6.HTML Compiler
1.
A Brief History
Of Web
Development
Once upon a time
jQuery (2006)
jQuery
▣ Started as DOM manipulation tool
▣ Became an all-in-one javascript library
□ without much forethoughts
▣ Our best friend back then, until..
The Era of Web
Apps
jQuery + Webapp = Headaches
▣ Structureless spaghetti code
□ Total code mess
▣ Selectors creating tight coupling
□ Non-reusable code
▣ Not enough high level abstractions
□ A lot of code required to be written
= TOTAL MESS
Backbone.js (2010)
backbone.js
▣ It brings structures to our code
▣ but still uses jQuery to handle the views
backbone.js
▣ Solved
□ No more spaghetti code
▣ NOT Solved
□ Selectors creating tight coupling
□ Not enough high level abstractions
What about High Level Abstractions?
▣ Backbone is unopinionated.
▣ It lacks the necessary tools to easily manage
any webapp above a certain threshold in
complexity
▣ The bottom line - Backbone asks you to write
A Lot More Code to get what you want
And the earth was without form,
and void; and darkness wasupon
the face of the deep
‘’
And the earth was without
form, and void; and darkness
wasupon the face of the deep
And God said:
Let there be light..
‘’
And the earth was without
form, and void; and darkness
wasupon the face of the deep
And God said:
Let there be light..
...and there was light
AngularJS
Initial release in 2009
Faster development
Quality code (structure and robustness)
Developed by Google
Trends
How come jQuery is still way more popular
than angular?
It’s not one or another
▣ Angular does not replace jQuery!
▣ jQuery library is the undoubted king of a DOM
manipulation
Angular’s Role
▣ Angular offers a comprehensive framework to
develop front-end applications
▣ Actually Angular provides jqLite out of the
box
□ a jQuery-like library that provides a subset of
jQuery functionality
2.
Introduction
What
AngularJS is all
about
‘’
AngularJS is:
1.a powerful Front-end
JavaScript framework
1.Extends HTML to build
complex web applications
1.Organizes JavaScript code
into reusable components
How things worked before:
JS
HTML
Structure
Behavior
CSSPresentation
HTMLInterface
CSSPresentation
JSLogic
How things works the Angular’s way:
Why Angular
▣ Component based - Code reuse
▣ Extends HTML by adding directives, custom
tags, attributes, expressions, templates within
HTML
▣ Data Binding and Dependency Injection
□ Everything is communicated automatically
▣ Dependency-injected code for easy testing
and TDD
The major features of AngularJS
▣ Easy Data Binding: Two way Data Binding
▣ Reusable Components - Directives
▣ Dependency injection
▣ Routing
▣ Templating
▣ Modules
▣ Controllers
▣ Services
▣ Expressions
▣ Filters
▣ Form Validation
▣ $scope, $http, $routeProvides..
3.
Architecture
What kind of
architecture
Angular use?
Template
Model
View
Compile
Change to View
updates the Model
Change to Model
updates the View
Two-way Binding
Two-way Binding
▣ Any changes in the scope 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
MVC? MVVM?
Model-View-Controller?
Model-View-ViewModel?
VIEW
define the data and methods that
will be available for the view
MODELbusiness logic
Html Template
$scope (VM)
Two-way Data-
Binding
Commands
Commands Change Notifications
What architecture is it?
MVW
Model View Whatever - Whatever works for you
4.
Getting Started
Getting started
▣ ng-app
<html ng-app=”myApp”>
<head>
<script src='angular.js'></script>
</head>
<body>
</body>
</html>
ng-app
▣ Use this directive to bootstrap an application
▣ Only one ng-app directive can be used per
HTML document
<html ng-app>
Markup {{ expression }}
▣ Double curly brace notation {{ }}
▣ Used to bind expressions to elements is built-
in Angular markup.
<div>1 + 2 = {{1+2}}</div>
Hello {{username}}
ng-model
▣ The ng-model directive binds an input,select,
textarea (or custom form control) to a
property on the scope
▣ Two-way binding
Data Binding
▣ ng-model
▣ ng-show
<html ng-app>
<head>
<script src='angular.js'></script>
</head>
<body>
<input ng-model='user.name'>
<div ng-show='user.name'>Hi {{user.name}}</div>
</body>
</html>
Modules (HTML side)
▣ All AngularJS JavaScript code is stored in
modules
▣ And a module is attached to a page
var app = angular.module('myApp', ['otherModule', 'anotherModule']);
<html ng-app="myApp"> ... </html>
Modules (Javascript)
▣ Modules are used to define services, controllers,
directives and filters
▣ Each module member is a constructor which can
inject other services
app.factory('myValues', function() {
return function() {
return [1,2,3,4,5,6];
};
});
app.filter('skipFirstValue', function() {
return function(data) {
return data.slice(1);
}
});
app.run(function($rootScope, myValues, skipFirstValueFilter) {
//this is called when the page is loaded
$rootScope.values = skipFirstValue(myValues());
});
$scope
▣ The scope is the glue between JavaScript and
HTML in AngularJS
▣ Anything placed on the $scope object can be
referenced in HTML
<div ng-controller="AppCtrl">
Hello, so far I have <strong>{{ totalApples }} </strong> apples.
<button ng-click="moreApples()">Give me more!</button>
</div>
app.controller('AppCtrl', function($scope) {
$scope.totalApples = 0;
$scope.moreApples = function() {
$scope.totalApples++;
}
});
$scope
Think of the scope as the memory for your HTML
Controllers
▣ Controllers are defined inside of a module like
all other services
app.controller('AppCtrl', function($scope) { ... });
Controllers
▣ And they can be referenced in HTML using
ng-controller (Or within routes..)
<html ng-app>
<head>
<script src='angular.js'></script>
<script src='controllers.js'></script>
</head>
<body ng-controller='UserController'>
<div>Hi {{user.name}}</div>
</body>
</html>
function UserController($scope) {
$scope.user = { name:'Larry' };
}
index.html
controllers.js
Ajax
AJAX using $http
▣ Use $http to perform an AJAX request
▣ The scope will automatically update itself
when $http returns gets a response
var app = angular.module('myApp', []);
app.controller('ColorsCtrl', function($scope, $http) {
$scope.colors = $http.get('/api/colors.json');
});
5.
Directives
The Magic
Begins..
No more HTML mess
Today’s websites have giant series of <div> with
extensive and exhaustive CSS, causing little
semantic clarity.
With Angular you can create your own tags and
attributes using Directives.
Directives
▣ Special custom components in HTML
▣ The directives can be placed in element
names, attributes, class names, as well as
comments.
▣ Directives are a way to teach HTML new
tricks.
<div my-precious-element></div>
Directives
▣ Handled in JavaScript via DOM manipulation
▣ A directive is just a function which executes
when the compiler encounters it in the DOM.
app.directive('myPreciousElement', function() {
return function($scope, element, attrs) {
element.bind('click', function() {
alert('clicked!');
});
};
});
Possible usage of directives
<rating max='5' model='stars.average'>
<tabs>
<tab title='Active tab' view='...'>
<tab title='Inactive tab' view='...'>
</tabs>
<tooltip content='messages.tip1'>
Built-in Directives
▣ AngularJS provides series of predefined HTML
components
▣ These components reduce much of the
JavaScript required to make HTML appear
dynamic
Some of the Built-in Directive
Components
▣ ng-repeat
▣ ng-show
▣ ng-hide
▣ ng-disabled
▣ ng-href
▣ ng-click
▣ ng-dbclick
▣ ng-mouseup
▣ ng-mouseover
▣ ng-focus
▣ ng-blur
▣ ...
6.
HTML Compiler
HTML Compiler
▣ Angular’s HTML compiler allows the
developer to teach the browser new HTML
syntax.
▣ The compiler allows you to attach behavior to
any HTML element or attribute and even
create new HTML elements or attributes with
custom behavior.
▣ Angular calls these behavior extensions
directives.
How the HTML Compiler works
▣ 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.
Exercise
http://www.learn-angular.org
Thanks!
Any questions?
You can find me at:
blog.avirancohen.com
facebook.com/MEvsWEB
Credits
▣ http://slides.com/gsklee/angularjs-a-brief-
introduction
▣ https://docs.google.com/presentation/d/1H
9u9xd0OE0W1o_5Aeug7uSR0AXXPidtWBQN
mpi_ZP9I

Mais conteĂșdo relacionado

Mais procurados

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig
 
Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·
Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·
Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·
Jeado Ko
 

Mais procurados (20)

Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Real World Web components
Real World Web componentsReal World Web components
Real World Web components
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·
Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·
Angular를 ᄒá…Șá†Żá„‹á…­á†Œá„’á…Ąá†« 웿 á„‘á…łá„…á…©á†«á„á…łá„ƒá…Ąá†« 귀발ᄀá…Ș 2.0ᄋᅊᄉᅄ á„ƒá…Ąá†Żá„…á…Ąá„Œá…”á†«á„Œá…„á†·
 
Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & Polymer
 
JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery Templates
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS
AngularJSAngularJS
AngularJS
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
Vue presentation
Vue presentationVue presentation
Vue presentation
 
Web components - An Introduction
Web components - An IntroductionWeb components - An Introduction
Web components - An Introduction
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
RequireJS
RequireJSRequireJS
RequireJS
 
Laravel 8 export data as excel file with example
Laravel 8 export data as excel file with exampleLaravel 8 export data as excel file with example
Laravel 8 export data as excel file with example
 

Semelhante a ME vs WEB - AngularJS Fundamentals

Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
Goutam Dey
 

Semelhante a ME vs WEB - AngularJS Fundamentals (20)

AngularJS.pptx
AngularJS.pptxAngularJS.pptx
AngularJS.pptx
 
Angular js
Angular jsAngular js
Angular js
 
Angular js
Angular jsAngular js
Angular js
 
Angular js
Angular jsAngular js
Angular js
 
Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]Full Stack React Workshop [CSSC x GDSC]
Full Stack React Workshop [CSSC x GDSC]
 
Angularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetupAngularjs for kolkata drupal meetup
Angularjs for kolkata drupal meetup
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
Angular js 2.0 beta
Angular js 2.0 betaAngular js 2.0 beta
Angular js 2.0 beta
 
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
 
AngularJs
AngularJsAngularJs
AngularJs
 
Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01Angularjs 131211063348-phpapp01
Angularjs 131211063348-phpapp01
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
AngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get startedAngularJS 101 - Everything you need to know to get started
AngularJS 101 - Everything you need to know to get started
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
Angular js for beginners
Angular js for beginnersAngular js for beginners
Angular js for beginners
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 

Último (20)

Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

ME vs WEB - AngularJS Fundamentals

  • 2. Hello! I am Aviran Cohen Full-stack Developer 7 years experience in web development blog.avirancohen.com facebook.com/MEvsWEB
  • 3. What we’ll cover 1.A brief history of web development 2.Introduction 3.Architecture 4.Getting Started 5.Directives 6.HTML Compiler
  • 4. 1. A Brief History Of Web Development
  • 5. Once upon a time
  • 7. jQuery ▣ Started as DOM manipulation tool ▣ Became an all-in-one javascript library □ without much forethoughts ▣ Our best friend back then, until..
  • 8. The Era of Web Apps
  • 9. jQuery + Webapp = Headaches ▣ Structureless spaghetti code □ Total code mess ▣ Selectors creating tight coupling □ Non-reusable code ▣ Not enough high level abstractions □ A lot of code required to be written
  • 12. backbone.js ▣ It brings structures to our code ▣ but still uses jQuery to handle the views
  • 13. backbone.js ▣ Solved □ No more spaghetti code ▣ NOT Solved □ Selectors creating tight coupling □ Not enough high level abstractions
  • 14. What about High Level Abstractions? ▣ Backbone is unopinionated. ▣ It lacks the necessary tools to easily manage any webapp above a certain threshold in complexity ▣ The bottom line - Backbone asks you to write A Lot More Code to get what you want
  • 15. And the earth was without form, and void; and darkness wasupon the face of the deep
  • 16. ‘’ And the earth was without form, and void; and darkness wasupon the face of the deep And God said: Let there be light..
  • 17. ‘’ And the earth was without form, and void; and darkness wasupon the face of the deep And God said: Let there be light..
  • 19. AngularJS Initial release in 2009 Faster development Quality code (structure and robustness) Developed by Google
  • 21. How come jQuery is still way more popular than angular?
  • 22. It’s not one or another ▣ Angular does not replace jQuery! ▣ jQuery library is the undoubted king of a DOM manipulation
  • 23. Angular’s Role ▣ Angular offers a comprehensive framework to develop front-end applications ▣ Actually Angular provides jqLite out of the box □ a jQuery-like library that provides a subset of jQuery functionality
  • 25. ‘’ AngularJS is: 1.a powerful Front-end JavaScript framework 1.Extends HTML to build complex web applications 1.Organizes JavaScript code into reusable components
  • 26. How things worked before: JS HTML Structure Behavior CSSPresentation
  • 28. Why Angular ▣ Component based - Code reuse ▣ Extends HTML by adding directives, custom tags, attributes, expressions, templates within HTML ▣ Data Binding and Dependency Injection □ Everything is communicated automatically ▣ Dependency-injected code for easy testing and TDD
  • 29. The major features of AngularJS ▣ Easy Data Binding: Two way Data Binding ▣ Reusable Components - Directives ▣ Dependency injection ▣ Routing ▣ Templating ▣ Modules ▣ Controllers ▣ Services ▣ Expressions ▣ Filters ▣ Form Validation ▣ $scope, $http, $routeProvides..
  • 31. Template Model View Compile Change to View updates the Model Change to Model updates the View Two-way Binding
  • 32. Two-way Binding ▣ Any changes in the scope 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
  • 34. VIEW define the data and methods that will be available for the view MODELbusiness logic Html Template $scope (VM) Two-way Data- Binding Commands Commands Change Notifications What architecture is it?
  • 35. MVW Model View Whatever - Whatever works for you
  • 37. Getting started ▣ ng-app <html ng-app=”myApp”> <head> <script src='angular.js'></script> </head> <body> </body> </html>
  • 38. ng-app ▣ Use this directive to bootstrap an application ▣ Only one ng-app directive can be used per HTML document <html ng-app>
  • 39. Markup {{ expression }} ▣ Double curly brace notation {{ }} ▣ Used to bind expressions to elements is built- in Angular markup. <div>1 + 2 = {{1+2}}</div> Hello {{username}}
  • 40. ng-model ▣ The ng-model directive binds an input,select, textarea (or custom form control) to a property on the scope ▣ Two-way binding
  • 41. Data Binding ▣ ng-model ▣ ng-show <html ng-app> <head> <script src='angular.js'></script> </head> <body> <input ng-model='user.name'> <div ng-show='user.name'>Hi {{user.name}}</div> </body> </html>
  • 42. Modules (HTML side) ▣ All AngularJS JavaScript code is stored in modules ▣ And a module is attached to a page var app = angular.module('myApp', ['otherModule', 'anotherModule']); <html ng-app="myApp"> ... </html>
  • 43. Modules (Javascript) ▣ Modules are used to define services, controllers, directives and filters ▣ Each module member is a constructor which can inject other services app.factory('myValues', function() { return function() { return [1,2,3,4,5,6]; }; }); app.filter('skipFirstValue', function() { return function(data) { return data.slice(1); } }); app.run(function($rootScope, myValues, skipFirstValueFilter) { //this is called when the page is loaded $rootScope.values = skipFirstValue(myValues()); });
  • 44. $scope ▣ The scope is the glue between JavaScript and HTML in AngularJS ▣ Anything placed on the $scope object can be referenced in HTML <div ng-controller="AppCtrl"> Hello, so far I have <strong>{{ totalApples }} </strong> apples. <button ng-click="moreApples()">Give me more!</button> </div> app.controller('AppCtrl', function($scope) { $scope.totalApples = 0; $scope.moreApples = function() { $scope.totalApples++; } });
  • 45. $scope Think of the scope as the memory for your HTML
  • 46. Controllers ▣ Controllers are defined inside of a module like all other services app.controller('AppCtrl', function($scope) { ... });
  • 47. Controllers ▣ And they can be referenced in HTML using ng-controller (Or within routes..) <html ng-app> <head> <script src='angular.js'></script> <script src='controllers.js'></script> </head> <body ng-controller='UserController'> <div>Hi {{user.name}}</div> </body> </html> function UserController($scope) { $scope.user = { name:'Larry' }; } index.html controllers.js
  • 48. Ajax
  • 49. AJAX using $http ▣ Use $http to perform an AJAX request ▣ The scope will automatically update itself when $http returns gets a response var app = angular.module('myApp', []); app.controller('ColorsCtrl', function($scope, $http) { $scope.colors = $http.get('/api/colors.json'); });
  • 51. No more HTML mess Today’s websites have giant series of <div> with extensive and exhaustive CSS, causing little semantic clarity. With Angular you can create your own tags and attributes using Directives.
  • 52. Directives ▣ Special custom components in HTML ▣ The directives can be placed in element names, attributes, class names, as well as comments. ▣ Directives are a way to teach HTML new tricks. <div my-precious-element></div>
  • 53. Directives ▣ Handled in JavaScript via DOM manipulation ▣ A directive is just a function which executes when the compiler encounters it in the DOM. app.directive('myPreciousElement', function() { return function($scope, element, attrs) { element.bind('click', function() { alert('clicked!'); }); }; });
  • 54. Possible usage of directives <rating max='5' model='stars.average'> <tabs> <tab title='Active tab' view='...'> <tab title='Inactive tab' view='...'> </tabs> <tooltip content='messages.tip1'>
  • 55. Built-in Directives ▣ AngularJS provides series of predefined HTML components ▣ These components reduce much of the JavaScript required to make HTML appear dynamic
  • 56. Some of the Built-in Directive Components ▣ ng-repeat ▣ ng-show ▣ ng-hide ▣ ng-disabled ▣ ng-href ▣ ng-click ▣ ng-dbclick ▣ ng-mouseup ▣ ng-mouseover ▣ ng-focus ▣ ng-blur ▣ ...
  • 58. HTML Compiler ▣ Angular’s HTML compiler allows the developer to teach the browser new HTML syntax. ▣ The compiler allows you to attach behavior to any HTML element or attribute and even create new HTML elements or attributes with custom behavior. ▣ Angular calls these behavior extensions directives.
  • 59. How the HTML Compiler works ▣ 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.
  • 61. Thanks! Any questions? You can find me at: blog.avirancohen.com facebook.com/MEvsWEB