SlideShare a Scribd company logo
Malang Frontend Developer
Pengenalan AngularJs
(versi 1.5.x)
Presented by : Edi Santoso
Events :
Meetup 5 February 2016
Dilo Malang
About Me
angular.module('profile')
.controller('ProfileCtrl', function ProfileCtrl($scope, profileService) {
'use strict';
$scope.profile = {
Name: 'Edi Santoso',
Current: 'Lead Developer at Kodesoft',
Past: 'Frontend Developer at PT Alfasoft',
Education: 'only graduates of vocational high schools',
Summary: 'I have more than 3 years of being in the ' +
'web development with some of the capabilities of the frontend and' +
'the backend technology.',
Email: 'edicyber@gmail.com',
Site: 'http://kodesoft.co.id/',
Github: 'https://github.com/cyberid41',
LinkedIn: 'https://id.linkedin.com/in/cyberid41',
Twitter: 'http://twitter.com/cyberid41'
};
});
February '16 Meetup Malang Frontend Developer
Why Angular?
To create properly architectured and
maintainable web applications
February '16 Meetup Malang Frontend Developer
Why Angular?
Defines numerous ways to organize
web application at client side
February '16 Meetup Malang Frontend Developer
Why Angular?
Encourage MVC/MVVM design
pattern
February '16 Meetup Malang Frontend Developer
Why Angular?
Good for Single Page Apps
February '16 Meetup Malang Frontend Developer
Why Angular?
https://github.com/showcases/front-end-javascript-frameworks
February '16 Meetup Malang Frontend Developer
Key Features
● Declarative HTML approach
● Easy Data Binding : Two way Data Binding
● Reusable Components
● MVC/MVVM Design Pattern
● Dependency Injection
● End to end Integration Testing / Unit Testing
February '16 Meetup Malang Frontend Developer
Key Features
● Routing
● Templating
● Modules
● Services
● Expressions
● Filters
● Directives
● Form Validation
February '16 Meetup Malang Frontend Developer
Declarative HTML
<!doctype html>
<html ng-app="todoApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="todo.js"></script>
<link rel="stylesheet" href="todo.css">
</head>
<body>
<h2>Todo</h2>
<div ng-controller="TodoListController as todoList">
<span>{{todoList.remaining()}} of {{todoList.todos.length}} remaining</span>
[ <a href="" ng-click="todoList.archive()">archive</a> ]
<ul class="unstyled">
<li ng-repeat="todo in todoList.todos">
<input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
<form ng-submit="todoList.addTodo()">
<input type="text" ng-model="todoList.todoText" size="30"
placeholder="add new todo here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
</body>
</html>
February '16 Meetup Malang Frontend Developer
Declarative HTML
<!doctype html>
<html ng-app="todoApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="todo.js"></script>
<link rel="stylesheet" href="todo.css">
</head>
<body>
<h2>Todo</h2>
<div ng-controller="TodoListController as todoList">
<span>{{todoList.remaining()}} of {{todoList.todos.length}} remaining</span>
[ <a href="" ng-click="todoList.archive()">archive</a> ]
<ul class="unstyled">
<li ng-repeat="todo in todoList.todos">
<input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
<form ng-submit="todoList.addTodo()">
<input type="text" ng-model="todoList.todoText" size="30"
placeholder="add new todo here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
</body>
</html>
February '16 Meetup Malang Frontend Developer
Declarative HTML
<!doctype html>
<html ng-app="todoApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
<script src="todo.js"></script>
<link rel="stylesheet" href="todo.css">
</head>
<body>
<h2>Todo</h2>
<div ng-controller="TodoListController as todoList">
<span>{{todoList.remaining()}} of {{todoList.todos.length}} remaining</span>
[ <a href="" ng-click="todoList.archive()">archive</a> ]
<ul class="unstyled">
<li ng-repeat="todo in todoList.todos">
<input type="checkbox" ng-model="todo.done">
<span class="done-{{todo.done}}">{{todo.text}}</span>
</li>
</ul>
<form ng-submit="todoList.addTodo()">
<input type="text" ng-model="todoList.todoText" size="30"
placeholder="add new todo here">
<input class="btn-primary" type="submit" value="add">
</form>
</div>
</body>
</html>
February '16 Meetup Malang Frontend Developer
Declarative Javascript
angular.module('todoApp', [])
.controller('TodoListController', function() {
var todoList = this;
todoList.todos = [
{text:'learn angular', done:true},
{text:'build an angular app', done:false}];
todoList.addTodo = function() {
todoList.todos.push({text:todoList.todoText, done:false});
todoList.todoText = '';
};
todoList.remaining = function() {
var count = 0;
angular.forEach(todoList.todos, function(todo) {
count += todo.done ? 0 : 1;
});
return count;
};
todoList.archive = function() {
var oldTodos = todoList.todos;
todoList.todos = [];
angular.forEach(oldTodos, function(todo) {
if (!todo.done) todoList.todos.push(todo);
});
};
});
Model View Controller (MVC)
Model View View Model (MVVM)
Data Binding and Interaction
Data Binding and Interaction
Scopes
Scope is an object that refers to the
application model. It is an execution
context for expressions.
Scopes
angular.module('scopeExample', [])
.controller('MyController', ['$scope', function($scope) {
$scope.username = 'World';
$scope.sayHello = function() {
$scope.greeting = 'Hello ' + $scope.username + '!';
};
}]);
// HTML
<div ng-controller="MyController">
Your name:
<input type="text" ng-model="username">
<button ng-click='sayHello()'>greet</button>
<hr>
{{greeting}}
</div>
Controllers
Controller is defined by a JavaScript
constructor function that is used to
augment the Angular Scope
Controllers
// javascript
var myApp = angular.module('myApp',[]);
myApp.controller('GreetingController', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
}]);
// HTML
<div ng-controller="MyController">
Your name:
<input type="text" ng-model="username">
<button ng-click='sayHello()'>greet</button>
<hr>
{{greeting}}
</div>
Services
Angular services are substitutable
objects that are wired together
using dependency injection (DI).
Services
angular.
module('myServiceModule', []).
controller('MyController', ['$scope','notify', function ($scope, notify) {
$scope.callNotify = function(msg) {
notify(msg);
};
}]).
factory('notify', ['$window', function(win) {
var msgs = [];
return function(msg) {
msgs.push(msg);
if (msgs.length == 3) {
win.alert(msgs.join("n"));
msgs = [];
}
};
}]);
<div id="simple" ng-controller="MyController">
<p>Let's try this simple notify service, injected into the controller...</p>
<input ng-init="message='test'" ng-model="message" >
<button ng-click="callNotify(message);">NOTIFY</button>
<p>(you have to click 3 times to see an alert)</p>
</div>
Directives
<ul class="phones">
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp">
<span>{{phone.name}}</span>
<p>{{phone.snippet}}</p>
</li>
</ul>
ngRepeat
Filters
<ul class="phones">
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp">
<span>{{phone.name | uppercase}}</span>
<p>{{phone.snippet}}</p>
</li>
</ul>
Filters - Uppercase
Modules
Modules and ngApp
<div ng-app="myApp">
<div>
{{ 'World' | greet }}
</div>
</div>
// declare a module
var myAppModule = angular.module('myApp', []);
// configure the module.
// in this example we will create a greeting filter
myAppModule.filter('greet', function() {
return function(name) {
return 'Hello, ' + name + '!';
};
});
Dependency Injection
Dependency Injection (DI) is a software
design pattern that deals with how
components get hold of their
dependencies.
Dependency Injection
Dependency Injection (DI) is a software
design pattern that deals with how
components get hold of their
dependencies.
Dependency Injection
// services
var phonecatServices = angular.module('phonecatServices', ['ngResource']);
phonecatServices.factory('Phone', ['$resource',
function($resource){
return $resource('phones/:phoneId.json', {}, {
query: {method:'GET', params:{phoneId:'phones'}, isArray:true}
});
}]);
// controller
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl', ['$scope', 'Phone', function($scope, Phone)
{
$scope.phones = Phone.query();
$scope.orderProp = 'age';
}]);
Routing
var phonecatApp = angular.module('phonecatApp', [
'ngRoute',
'phonecatControllers'
]);
phonecatApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'partials/phone-list.html',
controller: 'PhoneListCtrl'
}).
when('/phones/:phoneId', {
templateUrl: 'partials/phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
otherwise({
redirectTo: '/phones'
});
}]);
Finish...
Credits
http://www.slideshare.net/bolshchikov/angularjs-basics-with-example
http://www.slideshare.net/sbegaudeau/angular-js-101-everything-you-need-to-know-to-get-started
http://www.slideshare.net/manishekhawat/angularjs-22960631
https://docs.angularjs.org/
https://www.google.co.id/
Our Community
Malang PHP
https://www.facebook.com/groups/mphug/
MalangJs
https://www.facebook.com/groups/malangjs/
Official sites
http://malangphp.org/
Stay in touch...
@cyberid41
fb.com/cyberid41
id.linkedin.com/in/cyberid41
http://github.com/cyberid41
Stay in touch...

More Related Content

PDF
Game jump: frontend introduction #1
PDF
Guia de Sobrevivência JS no mundo Open Source
PPTX
webstudy jquery
PDF
MVC pattern for widgets
PDF
API-Entwicklung bei XING
PDF
HTML5 and Mobile
PPTX
Using Components to Build Native-Quality HTML5 Apps
PDF
jQuery Internals + Cool Stuff
Game jump: frontend introduction #1
Guia de Sobrevivência JS no mundo Open Source
webstudy jquery
MVC pattern for widgets
API-Entwicklung bei XING
HTML5 and Mobile
Using Components to Build Native-Quality HTML5 Apps
jQuery Internals + Cool Stuff

What's hot (20)

PDF
[FEConf Korea 2017]Angular 컴포넌트 대화법
PDF
Javascript session june 2013 (iii) jquery json
PDF
JavaScript Library Overview
DOCX
Coisas para o blog
PDF
Devoxx 2014-webComponents
PDF
dojo.Patterns
PDF
Introducing jQuery
PDF
jQuery in the [Aol.] Enterprise
PDF
Declarative and standards-based web application development with the Ample SDK
PDF
State of jQuery '08
PDF
Dependency Management with RequireJS
PPTX
Dart and AngularDart
PDF
Angular js routing options
PPTX
JQuery
PPTX
Starting with jQuery
PPTX
AngulrJS Overview
PDF
Web internship Yii Framework
PPTX
Ext JS Introduction
PPTX
Twitter bootstrap
PPTX
Jquery Basics
[FEConf Korea 2017]Angular 컴포넌트 대화법
Javascript session june 2013 (iii) jquery json
JavaScript Library Overview
Coisas para o blog
Devoxx 2014-webComponents
dojo.Patterns
Introducing jQuery
jQuery in the [Aol.] Enterprise
Declarative and standards-based web application development with the Ample SDK
State of jQuery '08
Dependency Management with RequireJS
Dart and AngularDart
Angular js routing options
JQuery
Starting with jQuery
AngulrJS Overview
Web internship Yii Framework
Ext JS Introduction
Twitter bootstrap
Jquery Basics
Ad

Viewers also liked (20)

PDF
Blnin formation-blender-les-bases
PDF
Los Carteles Luminosos Para Tiendas Y Comercios Atraen Mas La Atencion
PDF
Tenemos derechos humanos
PDF
Transsexuel(le)s : conditions et style de vie, santé perçue et comportements ...
DOCX
documento del proyecto
PDF
Boletín Informativo 09 de Agosto 2009
PDF
Catalogo desayunos de gustó
PPTX
Royal brinkman partner day
PPT
Recursos fotograficos
PPTX
Overview of the data pilot and OpenAIRE tools, Elly Dijk and Marjan Grootveld...
PDF
Business Video Marketing Report: The Definitive B2B Marketer’s Guide to Using...
PDF
Estrategias para potenciar la competencia lectora
PDF
Taller herramientas de comunicación para mejorar la gestión de las organizaci...
PDF
Los mejores precios en Internet Preciolandia . Visitanos
PDF
Presentación Pasarela Punta del Este 2015
PDF
Xcode magazine 3
PDF
Cnil - Guide Travail
PDF
Atajos autocad
Blnin formation-blender-les-bases
Los Carteles Luminosos Para Tiendas Y Comercios Atraen Mas La Atencion
Tenemos derechos humanos
Transsexuel(le)s : conditions et style de vie, santé perçue et comportements ...
documento del proyecto
Boletín Informativo 09 de Agosto 2009
Catalogo desayunos de gustó
Royal brinkman partner day
Recursos fotograficos
Overview of the data pilot and OpenAIRE tools, Elly Dijk and Marjan Grootveld...
Business Video Marketing Report: The Definitive B2B Marketer’s Guide to Using...
Estrategias para potenciar la competencia lectora
Taller herramientas de comunicación para mejorar la gestión de las organizaci...
Los mejores precios en Internet Preciolandia . Visitanos
Presentación Pasarela Punta del Este 2015
Xcode magazine 3
Cnil - Guide Travail
Atajos autocad
Ad

Similar to Pengenalan AngularJS (20)

PDF
Introduction to AngularJS
PDF
Nicolas Embleton, Advanced Angular JS
PDF
gDayX - Advanced angularjs
PPTX
Getting Started with Angular JS
PDF
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
PPTX
Angular Workshop_Sarajevo2
PPTX
AngularJS One Day Workshop
PPTX
01 startoff angularjs
PDF
GDayX - Advanced Angular.JS
PDF
Introduction to angular js
PPTX
Basics of AngularJS
PDF
Get AngularJS Started!
PPTX
Angular js 1.0-fundamentals
PPTX
AngularJS.part1
PDF
Angularjs
PPTX
Angular js for Beginnners
PPTX
The AngularJS way
PPTX
Angular Presentation
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
PDF
AngularJS for Web and Mobile
Introduction to AngularJS
Nicolas Embleton, Advanced Angular JS
gDayX - Advanced angularjs
Getting Started with Angular JS
gDayX 2013 - Advanced AngularJS - Nicolas Embleton
Angular Workshop_Sarajevo2
AngularJS One Day Workshop
01 startoff angularjs
GDayX - Advanced Angular.JS
Introduction to angular js
Basics of AngularJS
Get AngularJS Started!
Angular js 1.0-fundamentals
AngularJS.part1
Angularjs
Angular js for Beginnners
The AngularJS way
Angular Presentation
Learning AngularJS - Complete coverage of AngularJS features and concepts
AngularJS for Web and Mobile

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
System and Network Administration Chapter 2
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
history of c programming in notes for students .pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Transform Your Business with a Software ERP System
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
AI in Product Development-omnex systems
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Digital Strategies for Manufacturing Companies
medical staffing services at VALiNTRY
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
ai tools demonstartion for schools and inter college
System and Network Administration Chapter 2
VVF-Customer-Presentation2025-Ver1.9.pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
history of c programming in notes for students .pptx
Design an Analysis of Algorithms I-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Transform Your Business with a Software ERP System
Design an Analysis of Algorithms II-SECS-1021-03
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
AI in Product Development-omnex systems
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Operating system designcfffgfgggggggvggggggggg
Digital Strategies for Manufacturing Companies

Pengenalan AngularJS

  • 2. About Me angular.module('profile') .controller('ProfileCtrl', function ProfileCtrl($scope, profileService) { 'use strict'; $scope.profile = { Name: 'Edi Santoso', Current: 'Lead Developer at Kodesoft', Past: 'Frontend Developer at PT Alfasoft', Education: 'only graduates of vocational high schools', Summary: 'I have more than 3 years of being in the ' + 'web development with some of the capabilities of the frontend and' + 'the backend technology.', Email: 'edicyber@gmail.com', Site: 'http://kodesoft.co.id/', Github: 'https://github.com/cyberid41', LinkedIn: 'https://id.linkedin.com/in/cyberid41', Twitter: 'http://twitter.com/cyberid41' }; });
  • 3. February '16 Meetup Malang Frontend Developer Why Angular? To create properly architectured and maintainable web applications
  • 4. February '16 Meetup Malang Frontend Developer Why Angular? Defines numerous ways to organize web application at client side
  • 5. February '16 Meetup Malang Frontend Developer Why Angular? Encourage MVC/MVVM design pattern
  • 6. February '16 Meetup Malang Frontend Developer Why Angular? Good for Single Page Apps
  • 7. February '16 Meetup Malang Frontend Developer Why Angular? https://github.com/showcases/front-end-javascript-frameworks
  • 8. February '16 Meetup Malang Frontend Developer Key Features ● Declarative HTML approach ● Easy Data Binding : Two way Data Binding ● Reusable Components ● MVC/MVVM Design Pattern ● Dependency Injection ● End to end Integration Testing / Unit Testing
  • 9. February '16 Meetup Malang Frontend Developer Key Features ● Routing ● Templating ● Modules ● Services ● Expressions ● Filters ● Directives ● Form Validation
  • 10. February '16 Meetup Malang Frontend Developer Declarative HTML <!doctype html> <html ng-app="todoApp"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script> <script src="todo.js"></script> <link rel="stylesheet" href="todo.css"> </head> <body> <h2>Todo</h2> <div ng-controller="TodoListController as todoList"> <span>{{todoList.remaining()}} of {{todoList.todos.length}} remaining</span> [ <a href="" ng-click="todoList.archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todoList.todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="todoList.addTodo()"> <input type="text" ng-model="todoList.todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body> </html>
  • 11. February '16 Meetup Malang Frontend Developer Declarative HTML <!doctype html> <html ng-app="todoApp"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script> <script src="todo.js"></script> <link rel="stylesheet" href="todo.css"> </head> <body> <h2>Todo</h2> <div ng-controller="TodoListController as todoList"> <span>{{todoList.remaining()}} of {{todoList.todos.length}} remaining</span> [ <a href="" ng-click="todoList.archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todoList.todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="todoList.addTodo()"> <input type="text" ng-model="todoList.todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body> </html>
  • 12. February '16 Meetup Malang Frontend Developer Declarative HTML <!doctype html> <html ng-app="todoApp"> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script> <script src="todo.js"></script> <link rel="stylesheet" href="todo.css"> </head> <body> <h2>Todo</h2> <div ng-controller="TodoListController as todoList"> <span>{{todoList.remaining()}} of {{todoList.todos.length}} remaining</span> [ <a href="" ng-click="todoList.archive()">archive</a> ] <ul class="unstyled"> <li ng-repeat="todo in todoList.todos"> <input type="checkbox" ng-model="todo.done"> <span class="done-{{todo.done}}">{{todo.text}}</span> </li> </ul> <form ng-submit="todoList.addTodo()"> <input type="text" ng-model="todoList.todoText" size="30" placeholder="add new todo here"> <input class="btn-primary" type="submit" value="add"> </form> </div> </body> </html>
  • 13. February '16 Meetup Malang Frontend Developer Declarative Javascript angular.module('todoApp', []) .controller('TodoListController', function() { var todoList = this; todoList.todos = [ {text:'learn angular', done:true}, {text:'build an angular app', done:false}]; todoList.addTodo = function() { todoList.todos.push({text:todoList.todoText, done:false}); todoList.todoText = ''; }; todoList.remaining = function() { var count = 0; angular.forEach(todoList.todos, function(todo) { count += todo.done ? 0 : 1; }); return count; }; todoList.archive = function() { var oldTodos = todoList.todos; todoList.todos = []; angular.forEach(oldTodos, function(todo) { if (!todo.done) todoList.todos.push(todo); }); }; });
  • 15. Model View View Model (MVVM)
  • 16. Data Binding and Interaction
  • 17. Data Binding and Interaction
  • 18. Scopes Scope is an object that refers to the application model. It is an execution context for expressions.
  • 19. Scopes angular.module('scopeExample', []) .controller('MyController', ['$scope', function($scope) { $scope.username = 'World'; $scope.sayHello = function() { $scope.greeting = 'Hello ' + $scope.username + '!'; }; }]); // HTML <div ng-controller="MyController"> Your name: <input type="text" ng-model="username"> <button ng-click='sayHello()'>greet</button> <hr> {{greeting}} </div>
  • 20. Controllers Controller is defined by a JavaScript constructor function that is used to augment the Angular Scope
  • 21. Controllers // javascript var myApp = angular.module('myApp',[]); myApp.controller('GreetingController', ['$scope', function($scope) { $scope.greeting = 'Hola!'; }]); // HTML <div ng-controller="MyController"> Your name: <input type="text" ng-model="username"> <button ng-click='sayHello()'>greet</button> <hr> {{greeting}} </div>
  • 22. Services Angular services are substitutable objects that are wired together using dependency injection (DI).
  • 23. Services angular. module('myServiceModule', []). controller('MyController', ['$scope','notify', function ($scope, notify) { $scope.callNotify = function(msg) { notify(msg); }; }]). factory('notify', ['$window', function(win) { var msgs = []; return function(msg) { msgs.push(msg); if (msgs.length == 3) { win.alert(msgs.join("n")); msgs = []; } }; }]); <div id="simple" ng-controller="MyController"> <p>Let's try this simple notify service, injected into the controller...</p> <input ng-init="message='test'" ng-model="message" > <button ng-click="callNotify(message);">NOTIFY</button> <p>(you have to click 3 times to see an alert)</p> </div>
  • 24. Directives <ul class="phones"> <li ng-repeat="phone in phones | filter:query | orderBy:orderProp"> <span>{{phone.name}}</span> <p>{{phone.snippet}}</p> </li> </ul> ngRepeat
  • 25. Filters <ul class="phones"> <li ng-repeat="phone in phones | filter:query | orderBy:orderProp"> <span>{{phone.name | uppercase}}</span> <p>{{phone.snippet}}</p> </li> </ul> Filters - Uppercase
  • 26. Modules Modules and ngApp <div ng-app="myApp"> <div> {{ 'World' | greet }} </div> </div> // declare a module var myAppModule = angular.module('myApp', []); // configure the module. // in this example we will create a greeting filter myAppModule.filter('greet', function() { return function(name) { return 'Hello, ' + name + '!'; }; });
  • 27. Dependency Injection Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies.
  • 28. Dependency Injection Dependency Injection (DI) is a software design pattern that deals with how components get hold of their dependencies.
  • 29. Dependency Injection // services var phonecatServices = angular.module('phonecatServices', ['ngResource']); phonecatServices.factory('Phone', ['$resource', function($resource){ return $resource('phones/:phoneId.json', {}, { query: {method:'GET', params:{phoneId:'phones'}, isArray:true} }); }]); // controller var phonecatControllers = angular.module('phonecatControllers', []); phonecatControllers.controller('PhoneListCtrl', ['$scope', 'Phone', function($scope, Phone) { $scope.phones = Phone.query(); $scope.orderProp = 'age'; }]);
  • 30. Routing var phonecatApp = angular.module('phonecatApp', [ 'ngRoute', 'phonecatControllers' ]); phonecatApp.config(['$routeProvider', function($routeProvider) { $routeProvider. when('/phones', { templateUrl: 'partials/phone-list.html', controller: 'PhoneListCtrl' }). when('/phones/:phoneId', { templateUrl: 'partials/phone-detail.html', controller: 'PhoneDetailCtrl' }). otherwise({ redirectTo: '/phones' }); }]);