SlideShare a Scribd company logo
Carlos Hernando
@chernando
Javascript
AngularJS
Google I/O 2013 - Design Decisions in AngularJS
http://youtu.be/HCR7i5F5L8c
AngularJS at a glance
Try AngularJS
View
Bootstrap
<!doctype html>!
<html>!
<body>!
<script src="angular.js"></script>!
</body>!
</html>
/app/index.html
Directives
<!doctype html>!
<html>!
<body ng-app>!
!
<input type="text" ng-model="name">!
!
<script src="angular.js"></script>!
</body>!
</html>
/app/index.html
Data binding
<!doctype html>!
<html>!
<body ng-app>!
<input type="text" ng-model="name">!
!
<p>Hello {{ name }}</p>!
!
<script src="angular.js"></script>!
</body>!
</html>
/app/index.html
step 0
Application Structure
'use strict';!
!
angular.module('tryitApp', []);
/app/scripts/app.js
Directives
<body ng-app="tryitApp"!
ng-init="talks = [!
{!
'id': 1,!
'title': 'Acto de Apertura',!
'author': '(Por confirmar)',!
'starts': '2014-03-17T10:00:00+0100',!
'ends': '2014-03-17T11:00:00+0100',!
'description': ''!
},!
…!
]">
/app/index.html
ng-repeat
<div ng-repeat="talk in talks">!
<h2>{{ talk.title }}</h2>!
!
<p class="meta">!
{{ talk.starts }}!
{{ talk.author }}!
</p>!
!
<p class="description">!
{{ talk.description }}!
</p>!
</div>
/app/index.html
Filters
<p class="meta">!
{{ talk.starts | date:'medium' }}!
{{ talk.author | uppercase}}!
</p>!
!
/app/index.html
ng-repeat & filters
<input type="text" ng-model="filterText">!
!
<div ng-repeat="talk in talks | !
filter:filterText |!
orderBy:'starts'">!
!
<h2>{{ talk.title }}</h2>!
<p class="meta">!
…!
</p>!
<p class="description">!
…!
</p>!
</div>
/app/index.html
Directives & Data-binding
<p class="description">!
<img class="pull-left"!
width="160"!
height="160"!
!
ng-src="images/{{ talk.image || 'robot.png' }}">!
!
{{ talk.description }}!
</p>
/app/index.html
step 1
No JavaScript
Controllers & Services
Controller: ScheduleCtrl
angular.module('tryitApp')!
.controller('ScheduleCtrl',!
function ($scope) {!
$scope.talks = […];!
}!
);!
/app/scripts/controllers/schedule.js
$scope
Controllers & Views
<body ng-app="tryitApp">!
!
<div class="container"!
ng-controller="ScheduleCtrl">!
!
<div ng-repeat="talk in talks …">!
<h2>{{ talk.title }}</h2>!
…!
</div>
/app/index.html
Service: Talks
angular.module('tryitApp')!
.service('Talks', function Talks() {!
var talks = [!
{!
'id': 1,!
'title': 'Acto de Apertura',!
'starts': new Date('2012-03-17T10:00:00+0100'),!
…!
}, …!
];!
!
this.query = function () {!
return talks;!
};!
});
/app/scripts/services/talks.js
Dependency Injection
angular.module('tryitApp')!
.controller('ScheduleCtrl',!
function ($scope, Talks) {!
$scope.talks = Talks.query();!
}!
);
/app/scripts/controllers/schedule.js
step 2
Testing
Service: Favorites
angular.module('tryitApp')!
.factory('Favorites', function ($log) {!
var favorites = [];!
!
function addTalk(talk) {!
…!
}!
!
function isIn(talk) {!
…!
}!
!
return {!
addTalk: addTalk,!
isIn: isIn,!
talks: function() {!
return favorites;!
},!
};!
});!
/app/scripts/controllers/schedule.js
Test: Favorites
describe('Service: Favorites', function () {!
!
beforeEach(module('tryitApp'));!
!
var Favorites,!
talk1 = { id: 1 },!
talk2 = { id: 2 };!
!
beforeEach(inject(function (_Favorites_) {!
Favorites = _Favorites_;!
}));!
!
it('should not add same talk twice', function () {!
expect(Favorites.talks().length).toBe(0);!
Favorites.addTalk(talk1);!
Favorites.addTalk(talk1);!
expect(Favorites.talks().length).toBe(1);!
});!
});!
/test/spec/services/favorites.js
Adding Favorites
angular.module('tryitApp')!
.controller('ScheduleCtrl',!
function ($scope, Talks, Favorites) {!
$scope.talks = Talks.query();!
$scope.favorites = Favorites;!
}!
);
/app/scripts/controllers/schedule.js
Adding Favorites
<p class="meta">!
{{ talk.starts | date:'medium' }}!
{{ talk.author }}!
!
<a ng-hide="favorites.isIn(talk)"!
ng-click="favorites.addTalk(talk)">!
Add to Favorites!
</a>!
!
</p>
/app/index.html
step 3
Routes & Views
Routes
angular.module('tryitApp', ['ngRoute'])!
.config(function ($routeProvider) {!
$routeProvider!
.when('/', {!
templateUrl: 'views/schedule.html',!
controller: 'ScheduleCtrl'!
})!
.when('/my-schedule', {!
templateUrl: 'views/schedule.html',!
controller: 'MyScheduleCtrl'!
})!
.otherwise({!
redirectTo: '/'!
});!
});!
/app/scripts/app.js
ng-view
<div class="container"!
ng-view="">!
</div>!
/app/index.html
views/schedule.html
<h1>Talks</h1>!
<p>!
<input type="text"ng-model="filterText">!
</p>!
<div ng-repeat="talk in talks | filter:filterText | orderBy:'starts'">!
<h2>{{ talk.title }}</h2>!
<p class="meta">!
<span class="date">{{ talk.starts | date:'medium' }}</span>!
<span class="author">{{ talk.author }}</span>!
<a ng-hide="favorites.isIn(talk)"!
ng-click="favorites.addTalk(talk)">!
Add to Favorites!
</a>!
</p>!
!
<p class="description">!
<img ng-src="images/{{ talk.image || 'robot_question.png' }}">!
{{ talk.description }}!
</p>!
</div>!
/app/views/schedule.html
MyScheduleCtrl
angular.module('tryitApp')!
.controller('MyScheduleCtrl',!
function ($scope, Favorites) {!
$scope.talks = Favorites.talks();!
$scope.favorites = Favorites;!
});
/app/scripts/controllers/myschedule.js
step 4
More…
• Directives
• Providers
• Config
• Constants
• Directives
• $watch & $apply
• Protractor
• Other modules:
• Resource
• Animation
• …
• …
Books
Questions?!?
https://github.com/chernando/tryit_angularjs/
https://speakerdeck.com/chernando/try-angularjs
Thanks!
About
This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 3.0 Unported
License. To view a copy of this license, visit http://
creativecommons.org/licenses/by-nc-sa/3.0/.
Product names, logos and trademarks of other
companies which are referenced in this document
remain the property of those other companies.

More Related Content

PPTX
Custom directive and scopes
DOCX
Controller in AngularJS
DOCX
Directives
PPTX
Angular js
DOCX
Understanding angular js $rootscope and $scope
DOCX
Shaping up with angular JS
DOCX
multiple views and routing
KEY
SproutCore is Awesome - HTML5 Summer DevFest
Custom directive and scopes
Controller in AngularJS
Directives
Angular js
Understanding angular js $rootscope and $scope
Shaping up with angular JS
multiple views and routing
SproutCore is Awesome - HTML5 Summer DevFest

What's hot (20)

PDF
AngularJS best-practices
DOCX
Built in filters
DOCX
Filters in AngularJS
PPTX
Automated layout testing using Galen Framework
PPTX
AngularJS Introduction
PPTX
Galen Framework - Responsive Design Automation
PDF
Angular Classy
PDF
PPTX
Why angular js Framework
PDF
PLAT-14 Forms Config, Customization, and Extension
PDF
Gettings started with the superheroic JavaScript library AngularJS
PPTX
Starting with angular js
PPTX
Top 10 Mistakes AngularJS Developers Make
PPTX
Angular js
PPTX
Angular js tutorial slides
PDF
Angular Best Practices v2
PPTX
Angular js
DOCX
What is $root scope in angularjs
ODP
AngularJs Crash Course
AngularJS best-practices
Built in filters
Filters in AngularJS
Automated layout testing using Galen Framework
AngularJS Introduction
Galen Framework - Responsive Design Automation
Angular Classy
Why angular js Framework
PLAT-14 Forms Config, Customization, and Extension
Gettings started with the superheroic JavaScript library AngularJS
Starting with angular js
Top 10 Mistakes AngularJS Developers Make
Angular js
Angular js tutorial slides
Angular Best Practices v2
Angular js
What is $root scope in angularjs
AngularJs Crash Course
Ad

Viewers also liked (6)

PDF
Metodologías Ágiles
PDF
E commretail 0.4
PDF
Startups intro
PDF
Enredate elx
KEY
Startups
PDF
Pitch rally
Metodologías Ágiles
E commretail 0.4
Startups intro
Enredate elx
Startups
Pitch rally
Ad

Similar to Try AngularJS (20)

PDF
Practical HTML5: Using It Today
PDF
Introduction to AngularJS
PDF
ParisJS #10 : RequireJS
PPTX
Angular1x and Angular 2 for Beginners
PDF
Course CodeSchool - Shaping up with Angular.js
PDF
Python for AngularJS
PDF
243329387 angular-docs
PPTX
Angular directive filter and routing
DOCX
Angular js
PDF
Modular Test-driven SPAs with Spring and AngularJS
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
PDF
Ng init | EPI Sousse
KEY
Building a real life application in node js
PDF
Javascript MVC & Backbone Tips & Tricks
PDF
AngularJS - Services
PDF
Velocity EU 2014 — Offline-first web apps
PPT
Building Single Page Application (SPA) with Symfony2 and AngularJS
PDF
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
PPT
Introduccion app engine con python
PDF
AngularJS interview questions
Practical HTML5: Using It Today
Introduction to AngularJS
ParisJS #10 : RequireJS
Angular1x and Angular 2 for Beginners
Course CodeSchool - Shaping up with Angular.js
Python for AngularJS
243329387 angular-docs
Angular directive filter and routing
Angular js
Modular Test-driven SPAs with Spring and AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
Ng init | EPI Sousse
Building a real life application in node js
Javascript MVC & Backbone Tips & Tricks
AngularJS - Services
Velocity EU 2014 — Offline-first web apps
Building Single Page Application (SPA) with Symfony2 and AngularJS
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
Introduccion app engine con python
AngularJS interview questions

More from Carlos Hernando (7)

PDF
Introduciendo Serverless en Proyectos Python
PDF
Microservicos: Cuándo y Cómo
PDF
Django tricks (2)
PDF
Bases de Datos en Java - Intro a Hibernate
PDF
Bases de Datos en Java - Intro a JDBC
PDF
Introducción rápida a SQL
PDF
Persistencia en Java - Serialización
Introduciendo Serverless en Proyectos Python
Microservicos: Cuándo y Cómo
Django tricks (2)
Bases de Datos en Java - Intro a Hibernate
Bases de Datos en Java - Intro a JDBC
Introducción rápida a SQL
Persistencia en Java - Serialización

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
A Presentation on Artificial Intelligence
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Network Security Unit 5.pdf for BCA BBA.
A Presentation on Artificial Intelligence
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Programs and apps: productivity, graphics, security and other tools
NewMind AI Weekly Chronicles - August'25-Week II
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
sap open course for s4hana steps from ECC to s4
Assigned Numbers - 2025 - Bluetooth® Document
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
The AUB Centre for AI in Media Proposal.docx
Mobile App Security Testing_ A Comprehensive Guide.pdf

Try AngularJS