SlideShare une entreprise Scribd logo
1  sur  45
Dev Storyteller presents:
Mark Freedman
http://about.com/MarkFreedman
Who Am I to Speak About
AngularJS?
Death by DOM Manipulation
(jQuery)
What is AngularJS?
Miško Hevery & Adam Abrons - 2009
Google Feedback - 2010
Why do I care?
MV Whatever
Getting AngularJS
(The easy way)
Canonical “HelloWorld”
Example
<!DOCTYPE html>
<html>
<head>
<title>Canonical Example</title>
</head>
<body>
<div data-ng-app>
<input type="text" data-ng-model="message">
<h1>{{message + " World"}}</h1>
</div>
<script src="angular.min.js"></script>
</body>
</html>
Directives:
Module (ngApp)
Model (ngModel)
Data Binding:
Model and $scope
Controllers
Dependency Injection
<!DOCTYPE html>
<html data-ng-app>
<head>
<title>Controller Example</title>
</head>
<body>
<div data-ng-controller="studentController">
<ul>
<li data-ng-repeat="student in students">
{{student.name}} is in classroom
{{student.classroom}}, and earned a grade of
{{student.grade}}.
</li>
</ul>
</div>
<script src="angular.min.js"></script>
<script src="studentController.js"></script>
</body>
</html>
function studentController($scope) {
$scope.students = [
{
name: "John Doh",
class: 6,
grade: 93
},
{
name: "Steve Smith",
class: 5,
grade: 72
},
{
name: "Jane Doe",
class: 7,
grade: 87
},
.
.
.
];
}
Built-In Filters
<!DOCTYPE html>
<html data-ng-app>
<head>
<title>Controller Example</title>
</head>
<body>
<div data-ng-controller=”studentController">
<input type="text" data-ng-model="search.name">
<ul>
<li data-ng-repeat="student in students | filter:search | orderBy:'grade':true">
{{student.name}} is in classroom
{{student.classroom}}, and earned a grade of
{{student.grade}}.
</li>
</ul>
</div>
<script src="angular.min.js"></script>
<script src="studentController.js"></script>
</body>
</html>
Routing and Deep Linking
$routeProvider
var app = angular.module("app", ["ngRoute"]);
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/home.html',
controller: 'HomeController’
}).
when('/classrooms', {
templateUrl: 'partials/classrooms.html',
controller: 'ClassroomController’
}).
when('/students/:classroom', {
templateUrl: 'partials/studentsClassrooms.html',
controller: 'StudentController’
}).
when('/students', {
templateUrl: 'partials/students.html',
controller: 'StudentController’
}).
otherwise({
redirectTo: '/’
});
}]);
View
<!DOCTYPE html>
<html data-ng-app="app">
<head>
<title>School Roster</title>
</head>
<body>
<h1>School Roster</h1>
<div data-ng-view />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script>
<script src="app.js"></script>
</body>
</html>
home.html
<a href="#/classrooms">List of Classrooms</a><p/>
<a href="#/students">List of Students</a>
classrooms.html
<h2>Classrooms</h2>
<h3 data-ng-repeat="classroom in classrooms | orderBy:'classroom'">
<a href="#/students/{{classroom}}">{{classroom}}</a>
</h3>
students.html
<h2>Students</h2>
Filter: <input type="text" data-ng-model="search.name">
<ul>
<li data-ng-click="displayStudentInfo(student)"
data-ng-repeat="student in students | filter:search | orderBy:'grade':true">
{{student.name}} is in classroom
{{student.classroom}}, and earned a grade of
{{student.grade}}.
</li>
</ul>
studentsClassroom.html
<h2>Students by Classroom - Room {{classroom}}</h2>
<ul>
<li data-ng-repeat="student in students | filter:classroom | orderBy:'name'">
{{student.name}} earned a grade of {{student.grade}}.
</li>
</ul>
app.controller("HomeController", function () {});
app.controller("ClassroomController", function ($scope) {
$scope.classrooms = [513, 602, 722];
});
app.controller("StudentController", function ($scope, $routeParams) {
$scope.students = [
{
name: "John Doh",
classroom: 602,
grade: 93
},
{
name: "Steve Smith",
classroom: 513,
grade: 72
},
.
.
.
];
$scope.displayStudentInfo = function(student) {
alert(student.name);
}
if ($routeParams.classroom) $scope.classroom = $routeParams.classroom;
});
Controller As
<!DOCTYPE html>
<html data-ng-app>
<head>
<title>Controller Example</title>
</head>
<body>
<div data-ng-controller="studentController as vm">
<ul>
<li data-ng-repeat="student in vm.students">
{{student.name}} is in classroom
{{student.classroom}}, and earned a grade of
{{student.grade}}.
</li>
</ul>
</div>
<script src="angular.min.js"></script>
<script src="studentControllerAs.js"></script>
</body>
</html>
function studentController() {
var vm = this;
vm.students = [
{
name: "John Doh",
class: 6,
grade: 93
},
{
name: "Steve Smith",
class: 5,
grade: 72
},
{
name: "Jane Doe",
class: 7,
grade: 87
},
.
.
.
];
}
Built-In Services
Custom Services
app.factory("studentRepository", function () {
var factoryInstance = {};
var students = [
{
name: "John Doh",
classroom: 602,
grade: 93
},
{
name: "Steve Smith",
classroom: 513,
grade: 72
},
.
.
.
];
factory.getStudents = function () {
return students;
}
return factoryInstance;
});
app.controller("StudentController",
function ($scope, $routeParams, studentRepository) {
$scope.students = studentRepository.getStudents();
$scope.displayStudentInfo = function(student) {
alert(student.name);
}
if ($routeParams.classroom) $scope.classroom = $routeParams.classroom;
});
Built-In Directives
https://docs.angularjs.org/api/ng/directive
http://angular-ui.github.io/
https://github.com/kendo-labs/angular-kendo
Custom Directives
…pretending he knows something.
app.directive("colorize", function () {
return {
restrict: "AE”,
scope: {
color: "="
},
template: "<span>" +
"<span style='color: {{color}};' data-ng-transclude></span>" +
"</span>",
transclude: true
};
});
<h2>Students</h2>
Filter: <input type="text" data-ng-model="search.name"><br/>
Color: <input type="text" data-ng-model="chosenColor"><br/>
<ul>
<li colorize color="chosenColor" data-ng-click="displayStudentInfo(student)”
data-ng-repeat="student in students | filter:search | orderBy:'grade':true">
{{student.name}} is in classroom
{{student.classroom}}, and earned a grade of
{{student.grade}}.
</li>
</ul>
app.directive("collapsible", function () {
return {
restrict: "E",
template: "<div>" +
"<h3 data-ng-click='toggleVisibility()'>{{title}}</h3>" +
"<div data-ng-show='visible' data-ng-transclude></div>" +
"</div>",
scope: {
title: "@”
},
replace: true,
link: function (scope, element, attrs, ctrls, transclude) {
transclude(scope.$parent, function(clone, scope) {
element.children().eq(1).empty();
element.children().append(clone);
});
},
controller: function ($scope) {
$scope.visible = true;
$scope.toggleVisibility = function () {
$scope.visible = !$scope.visible;
if (!$scope.visible) $scope.$parent.search.name = ””
};
},
transclude: true
};
});
<collapsible title="Toggle Filtering">
Filter: <input type="text" data-ng-model="search.name">
</collapsible>
E: <my-directive></my-directive>
A: <div my-directive></div>
C: <div class=“my-directive”></div>
M: <!-- directive: my-directive -->
Custom Filters
app.filter("spacer", function() {
return function(text) {
text = text.split("").join(" ");
return text;
};
});
<ul>
<li data-ng-click="displayStudentInfo(student)"
data-ng-repeat="student in students |
filter:search | orderBy:'grade':true">
{{student.name | spacer}} is in classroom
{{student.classroom}}, and earned a grade of
{{student.grade}}.
</li>
</ul>
Remote Data and $http
Promises
app.factory("studentRepository", function ($http) {
var factory = {};
factory.getStudents = function () {
return $http.get("http://localhost/students.json");
}
return factory;
});
app.controller("StudentController", function($scope, $routeParams, studentRepository)
{
studentRepository.getStudents().then(function (result) {
$scope.students = result.data;
});
$scope.displayStudentInfo = function(student) {
alert(student.name);
}
if ($routeParams.classroom) $scope.classroom = $routeParams.classroom;
});
Learning Resources
 AngularJS:
https://angularjs.org/
 How do I think in AngularJS…:
http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-
have-a-jquery-background
 Create an Angular App in Seconds with HotTowel:
http://www.johnpapa.net/hot-towel-angular/
 Angular App StructuringGuideline:
http://www.johnpapa.net/angular-app-structuring-guidelines/
 AngularJS - ng-conf 2014:
http://ng-conf.ng-learn.org/
 AngularJS on Google+:
https://plus.google.com/+AngularJS/posts

Contenu connexe

Tendances

Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testingsmontanari
 
Empower your App by Inheriting from Odoo Mixins
Empower your App by Inheriting from Odoo MixinsEmpower your App by Inheriting from Odoo Mixins
Empower your App by Inheriting from Odoo MixinsOdoo
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoRob Bontekoe
 
Dialogs in Android MVVM (14.11.2019)
Dialogs in Android MVVM (14.11.2019)Dialogs in Android MVVM (14.11.2019)
Dialogs in Android MVVM (14.11.2019)Vladislav Ermolin
 
jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');mikehostetler
 
GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4Heather Rock
 
Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentationScott Messinger
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletonGeorge Nguyen
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSbuttyx
 
Odoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo FrameworkOdoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo FrameworkElínAnna Jónasdóttir
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverSpike Brehm
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & AngularAlexe Bogdan
 

Tendances (20)

Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testing
 
Empower your App by Inheriting from Odoo Mixins
Empower your App by Inheriting from Odoo MixinsEmpower your App by Inheriting from Odoo Mixins
Empower your App by Inheriting from Odoo Mixins
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Ext JS Introduction
Ext JS IntroductionExt JS Introduction
Ext JS Introduction
 
Dialogs in Android MVVM (14.11.2019)
Dialogs in Android MVVM (14.11.2019)Dialogs in Android MVVM (14.11.2019)
Dialogs in Android MVVM (14.11.2019)
 
jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');jQuery('#knowledge').appendTo('#you');
jQuery('#knowledge').appendTo('#you');
 
GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4GDI Seattle - Intro to JavaScript Class 4
GDI Seattle - Intro to JavaScript Class 4
 
Knockout.js presentation
Knockout.js presentationKnockout.js presentation
Knockout.js presentation
 
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas EmbletongDayX 2013 - Advanced AngularJS - Nicolas Embleton
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
Odoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo FrameworkOdoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo Framework
 
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFGStHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
StHack 2014 - Mario "@0x6D6172696F" Heiderich - JSMVCOMFG
 
JavaScript Libraries
JavaScript LibrariesJavaScript Libraries
JavaScript Libraries
 
Introducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and serverIntroducing Rendr: Run your Backbone.js apps on the client and server
Introducing Rendr: Run your Backbone.js apps on the client and server
 
22 j query1
22 j query122 j query1
22 j query1
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 

En vedette

Iglesia Presbiteriana Getsemani
Iglesia Presbiteriana GetsemaniIglesia Presbiteriana Getsemani
Iglesia Presbiteriana Getsemanijpc6760
 
Copy crash course maribel gracia 6340.65 revised 1
Copy crash course maribel gracia 6340.65 revised 1Copy crash course maribel gracia 6340.65 revised 1
Copy crash course maribel gracia 6340.65 revised 1mgracia5
 
Casanova juanitap.~edtc6340.65copyrightrevision3
Casanova juanitap.~edtc6340.65copyrightrevision3Casanova juanitap.~edtc6340.65copyrightrevision3
Casanova juanitap.~edtc6340.65copyrightrevision3jpc6760
 
Copy crash course maribel gracia 6340.65 revised 3
Copy crash course maribel gracia 6340.65 revised 3Copy crash course maribel gracia 6340.65 revised 3
Copy crash course maribel gracia 6340.65 revised 3mgracia5
 
Sample Case Studies Without References
Sample Case Studies Without ReferencesSample Case Studies Without References
Sample Case Studies Without Referencesbohargrove
 
Copyright crash course
Copyright crash  courseCopyright crash  course
Copyright crash coursemgracia5
 
Copy crash course maribel gracia 6340.65 revised 5 [recovered]
Copy crash course maribel gracia 6340.65 revised 5 [recovered]Copy crash course maribel gracia 6340.65 revised 5 [recovered]
Copy crash course maribel gracia 6340.65 revised 5 [recovered]mgracia5
 
Copy crash course maribel gracia 6340.65 revised 2
Copy crash course maribel gracia 6340.65 revised 2Copy crash course maribel gracia 6340.65 revised 2
Copy crash course maribel gracia 6340.65 revised 2mgracia5
 
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia AldapeCopyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldapesoniaaldape
 

En vedette (9)

Iglesia Presbiteriana Getsemani
Iglesia Presbiteriana GetsemaniIglesia Presbiteriana Getsemani
Iglesia Presbiteriana Getsemani
 
Copy crash course maribel gracia 6340.65 revised 1
Copy crash course maribel gracia 6340.65 revised 1Copy crash course maribel gracia 6340.65 revised 1
Copy crash course maribel gracia 6340.65 revised 1
 
Casanova juanitap.~edtc6340.65copyrightrevision3
Casanova juanitap.~edtc6340.65copyrightrevision3Casanova juanitap.~edtc6340.65copyrightrevision3
Casanova juanitap.~edtc6340.65copyrightrevision3
 
Copy crash course maribel gracia 6340.65 revised 3
Copy crash course maribel gracia 6340.65 revised 3Copy crash course maribel gracia 6340.65 revised 3
Copy crash course maribel gracia 6340.65 revised 3
 
Sample Case Studies Without References
Sample Case Studies Without ReferencesSample Case Studies Without References
Sample Case Studies Without References
 
Copyright crash course
Copyright crash  courseCopyright crash  course
Copyright crash course
 
Copy crash course maribel gracia 6340.65 revised 5 [recovered]
Copy crash course maribel gracia 6340.65 revised 5 [recovered]Copy crash course maribel gracia 6340.65 revised 5 [recovered]
Copy crash course maribel gracia 6340.65 revised 5 [recovered]
 
Copy crash course maribel gracia 6340.65 revised 2
Copy crash course maribel gracia 6340.65 revised 2Copy crash course maribel gracia 6340.65 revised 2
Copy crash course maribel gracia 6340.65 revised 2
 
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia AldapeCopyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
Copyright Crash Course 1st revised ppt 6340.64 Sonia Aldape
 

Similaire à AngularJS On-Ramp

Backbone js in drupal core
Backbone js in drupal coreBackbone js in drupal core
Backbone js in drupal coreMarcin Wosinek
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile ProcessEyal Vardi
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsReturn on Intelligence
 
AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?Jim Duffy
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksHjörtur Hilmarsson
 
How to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI ComponentsHow to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI Componentscagataycivici
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IVisual Engineering
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014Dariusz Kalbarczyk
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenerytoddbr
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish MinutesDan Wahlin
 
Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Marcin Wosinek
 
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksJSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksMario Heiderich
 

Similaire à AngularJS On-Ramp (20)

Backbone js in drupal core
Backbone js in drupal coreBackbone js in drupal core
Backbone js in drupal core
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
AngularJS and SPA
AngularJS and SPAAngularJS and SPA
AngularJS and SPA
 
AngularJS Compile Process
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile Process
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.js
 
AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?AngularJS: What's the Big Deal?
AngularJS: What's the Big Deal?
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
How to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI ComponentsHow to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI Components
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
Valentine with AngularJS
Valentine with AngularJSValentine with AngularJS
Valentine with AngularJS
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Angular js
Angular jsAngular js
Angular js
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013
 
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating FrameworksJSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
 

Dernier

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
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-...Steffen Staab
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2
 
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 AidPhilip Schwarz
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Bert Jan Schrijver
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
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 studentsHimanshiGarg82
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 

Dernier (20)

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
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-...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
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
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
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
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

AngularJS On-Ramp

  • 1. Dev Storyteller presents: Mark Freedman http://about.com/MarkFreedman
  • 2. Who Am I to Speak About AngularJS?
  • 3. Death by DOM Manipulation (jQuery)
  • 4. What is AngularJS? Miško Hevery & Adam Abrons - 2009 Google Feedback - 2010
  • 5. Why do I care?
  • 9. <!DOCTYPE html> <html> <head> <title>Canonical Example</title> </head> <body> <div data-ng-app> <input type="text" data-ng-model="message"> <h1>{{message + " World"}}</h1> </div> <script src="angular.min.js"></script> </body> </html>
  • 13. <!DOCTYPE html> <html data-ng-app> <head> <title>Controller Example</title> </head> <body> <div data-ng-controller="studentController"> <ul> <li data-ng-repeat="student in students"> {{student.name}} is in classroom {{student.classroom}}, and earned a grade of {{student.grade}}. </li> </ul> </div> <script src="angular.min.js"></script> <script src="studentController.js"></script> </body> </html>
  • 14. function studentController($scope) { $scope.students = [ { name: "John Doh", class: 6, grade: 93 }, { name: "Steve Smith", class: 5, grade: 72 }, { name: "Jane Doe", class: 7, grade: 87 }, . . . ]; }
  • 16. <!DOCTYPE html> <html data-ng-app> <head> <title>Controller Example</title> </head> <body> <div data-ng-controller=”studentController"> <input type="text" data-ng-model="search.name"> <ul> <li data-ng-repeat="student in students | filter:search | orderBy:'grade':true"> {{student.name}} is in classroom {{student.classroom}}, and earned a grade of {{student.grade}}. </li> </ul> </div> <script src="angular.min.js"></script> <script src="studentController.js"></script> </body> </html>
  • 17. Routing and Deep Linking
  • 19. var app = angular.module("app", ["ngRoute"]); app.config(['$routeProvider', function ($routeProvider) { $routeProvider. when('/', { templateUrl: 'partials/home.html', controller: 'HomeController’ }). when('/classrooms', { templateUrl: 'partials/classrooms.html', controller: 'ClassroomController’ }). when('/students/:classroom', { templateUrl: 'partials/studentsClassrooms.html', controller: 'StudentController’ }). when('/students', { templateUrl: 'partials/students.html', controller: 'StudentController’ }). otherwise({ redirectTo: '/’ }); }]);
  • 20. View
  • 21. <!DOCTYPE html> <html data-ng-app="app"> <head> <title>School Roster</title> </head> <body> <h1>School Roster</h1> <div data-ng-view /> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular-route.min.js"></script> <script src="app.js"></script> </body> </html>
  • 22. home.html <a href="#/classrooms">List of Classrooms</a><p/> <a href="#/students">List of Students</a> classrooms.html <h2>Classrooms</h2> <h3 data-ng-repeat="classroom in classrooms | orderBy:'classroom'"> <a href="#/students/{{classroom}}">{{classroom}}</a> </h3> students.html <h2>Students</h2> Filter: <input type="text" data-ng-model="search.name"> <ul> <li data-ng-click="displayStudentInfo(student)" data-ng-repeat="student in students | filter:search | orderBy:'grade':true"> {{student.name}} is in classroom {{student.classroom}}, and earned a grade of {{student.grade}}. </li> </ul> studentsClassroom.html <h2>Students by Classroom - Room {{classroom}}</h2> <ul> <li data-ng-repeat="student in students | filter:classroom | orderBy:'name'"> {{student.name}} earned a grade of {{student.grade}}. </li> </ul>
  • 23. app.controller("HomeController", function () {}); app.controller("ClassroomController", function ($scope) { $scope.classrooms = [513, 602, 722]; }); app.controller("StudentController", function ($scope, $routeParams) { $scope.students = [ { name: "John Doh", classroom: 602, grade: 93 }, { name: "Steve Smith", classroom: 513, grade: 72 }, . . . ]; $scope.displayStudentInfo = function(student) { alert(student.name); } if ($routeParams.classroom) $scope.classroom = $routeParams.classroom; });
  • 25. <!DOCTYPE html> <html data-ng-app> <head> <title>Controller Example</title> </head> <body> <div data-ng-controller="studentController as vm"> <ul> <li data-ng-repeat="student in vm.students"> {{student.name}} is in classroom {{student.classroom}}, and earned a grade of {{student.grade}}. </li> </ul> </div> <script src="angular.min.js"></script> <script src="studentControllerAs.js"></script> </body> </html>
  • 26. function studentController() { var vm = this; vm.students = [ { name: "John Doh", class: 6, grade: 93 }, { name: "Steve Smith", class: 5, grade: 72 }, { name: "Jane Doe", class: 7, grade: 87 }, . . . ]; }
  • 29. app.factory("studentRepository", function () { var factoryInstance = {}; var students = [ { name: "John Doh", classroom: 602, grade: 93 }, { name: "Steve Smith", classroom: 513, grade: 72 }, . . . ]; factory.getStudents = function () { return students; } return factoryInstance; });
  • 30. app.controller("StudentController", function ($scope, $routeParams, studentRepository) { $scope.students = studentRepository.getStudents(); $scope.displayStudentInfo = function(student) { alert(student.name); } if ($routeParams.classroom) $scope.classroom = $routeParams.classroom; });
  • 33. app.directive("colorize", function () { return { restrict: "AE”, scope: { color: "=" }, template: "<span>" + "<span style='color: {{color}};' data-ng-transclude></span>" + "</span>", transclude: true }; });
  • 34. <h2>Students</h2> Filter: <input type="text" data-ng-model="search.name"><br/> Color: <input type="text" data-ng-model="chosenColor"><br/> <ul> <li colorize color="chosenColor" data-ng-click="displayStudentInfo(student)” data-ng-repeat="student in students | filter:search | orderBy:'grade':true"> {{student.name}} is in classroom {{student.classroom}}, and earned a grade of {{student.grade}}. </li> </ul>
  • 35. app.directive("collapsible", function () { return { restrict: "E", template: "<div>" + "<h3 data-ng-click='toggleVisibility()'>{{title}}</h3>" + "<div data-ng-show='visible' data-ng-transclude></div>" + "</div>", scope: { title: "@” }, replace: true, link: function (scope, element, attrs, ctrls, transclude) { transclude(scope.$parent, function(clone, scope) { element.children().eq(1).empty(); element.children().append(clone); }); }, controller: function ($scope) { $scope.visible = true; $scope.toggleVisibility = function () { $scope.visible = !$scope.visible; if (!$scope.visible) $scope.$parent.search.name = ”” }; }, transclude: true }; });
  • 36. <collapsible title="Toggle Filtering"> Filter: <input type="text" data-ng-model="search.name"> </collapsible>
  • 37. E: <my-directive></my-directive> A: <div my-directive></div> C: <div class=“my-directive”></div> M: <!-- directive: my-directive -->
  • 39. app.filter("spacer", function() { return function(text) { text = text.split("").join(" "); return text; }; });
  • 40. <ul> <li data-ng-click="displayStudentInfo(student)" data-ng-repeat="student in students | filter:search | orderBy:'grade':true"> {{student.name | spacer}} is in classroom {{student.classroom}}, and earned a grade of {{student.grade}}. </li> </ul>
  • 43. app.factory("studentRepository", function ($http) { var factory = {}; factory.getStudents = function () { return $http.get("http://localhost/students.json"); } return factory; });
  • 44. app.controller("StudentController", function($scope, $routeParams, studentRepository) { studentRepository.getStudents().then(function (result) { $scope.students = result.data; }); $scope.displayStudentInfo = function(student) { alert(student.name); } if ($routeParams.classroom) $scope.classroom = $routeParams.classroom; });
  • 45. Learning Resources  AngularJS: https://angularjs.org/  How do I think in AngularJS…: http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i- have-a-jquery-background  Create an Angular App in Seconds with HotTowel: http://www.johnpapa.net/hot-towel-angular/  Angular App StructuringGuideline: http://www.johnpapa.net/angular-app-structuring-guidelines/  AngularJS - ng-conf 2014: http://ng-conf.ng-learn.org/  AngularJS on Google+: https://plus.google.com/+AngularJS/posts

Notes de l'éditeur

  1. After the initial learning curve, your productivity will get a huge boost, especially when using some of the “seeding” options out there, such as John Papa’s HotTowel. The JavaScript in the apps I’ve written are maybe 20% the size of what they were when I was using jQuery to manipulate everything. Yes, you can finally, reliably unit test your JavaScript! AngularJS was build from the start to support testability, and includes mocking features to assist. Most importantly – they have cool release names 
  2. Although many consider it an MVC framework due to the view, controller, and mode ($scope) parts of it, many consider it an MVVM framework due to its two-way binding. I think it provides the best of both worlds.
  3. The easiest way is to install HotTowel, which comes with a seed app structure. But you can download and install manually, or use a CDN (content delivery network). Since I’m going to be showing the basics, I’ll keep this simple, so we don’t have to focus on the details of what a seeded environment such as HotTowel gives us.
  4. canonical.html
  5. ng-app wraps the part of HTML you want handled by AngularJS. In this example, we’re only wrapping a DIV, but normally, we’d wrap the entire page by placing it on the HTML element. In order to conform to HTML 5’s standards, and to not have Visual Studio complain, you can precede AngularJS’s built-in attributes with “data-” (data-ng-app). Data binding is done using the “handlebar” notation within your HTML. Simple two-way data binding is done using the ngModel directive in conjunction with the handlebar notation. If you dig into the AngularJS JavaScript (I mean, *really* dig), you’ll see that, among a lot of other logic, the ngModel directive includes logic to capture “model” updates on each keystroke.