Documente Academic
Documente Profesional
Documente Cultură
Dan Wahlin
Dan Wahlin
Blog
http://weblogs.asp.net/dwahlin
Twitter
@DanWahlin
http://angularjs.org
Transclusion
Scope
Linking
Restrictio
n
Directive
Agenda
AngularJS Features
Getting Started
Directives, Filters and Data Binding
Views, Controllers and Scope
Modules, Routes and Factories
Getting Started
http://www.myspa.com
View
View
View
View
History
Module Loading
Caching
Object Modeling
Data Binding
Ajax/Promises
View Loading
Data Binding
jqLite
MVC
Templates
Routing
History
Testing
Factories
ngularJS is a full-featured
SPA framework
ViewModel
Controllers
Controllers
Views
Directives
Directives, Filters
and Data Binding
Data Binding
Expression
<html data-ng-app="">
...
<div class="container"
data-ng-init="names=['Dave','Napur','Heedy','Shriva']">
<h3>Looping with the ng-repeat Directive</h3>
<ul>
<li data-ng-repeat="name in names">{{ name }}</li>
</ul>
</div>
...
</html>
Iterate through
names
Using Filters
<ul>
<li data-ng-repeat="cust in customers |
orderBy:'name'">
Order
{{ cust.name | uppercase }}
customers by
</li>
name
</ul>
property
Filter customers
by model value
Demo
Views, Controllers
and Scope
$scope
Controller
Define the
<div class="container" data-ng-controller="SimpleController">
<h3>Adding a Simple Controller</h3>
controller to
<ul>
use
<li data-ng-repeat="cust in customers">
{{ cust.name }} - {{ cust.city }}
</li>
Access $scope
$scope
</ul>
injected
</div>
dynamically
Basic
<script>
controller
function SimpleController($scope) {
$scope.customers = [
{ name: 'Dave Jones', city: 'Phoenix' },
{ name: 'Jamie Riley', city: 'Atlanta' },
{ name: 'Heedy Wahlin', city: 'Chandler' },
{ name: 'Thomas Winter', city: 'Seattle' }
];
}
</script>
Demo
Modules, Routes
and Factories
Module
Config
Routes
View
Directives
$scope
Controller
*Factory
Module
Config
Filter
Directive
Factory
Service
Routes
Provider
Value
Controller
Creating a Module
What's the
Array for?
Define a
Controller
Define a
Module
demoApp.controller('SimpleController', function
($scope) {
$scope.customers = [
{ name: 'Dave Jones', city: 'Phoenix' },
{ name: 'Jamie Riley', city: 'Atlanta' },
{ name: 'Heedy Wahlin', city: 'Chandler' },
{ name: 'Thomas Winter', city: 'Seattle' }
];
});
View1
/view2
View2
/view3
/view1
/view4
View4
View3
Defining Routes
var demoApp = angular.module('demoApp', ['ngRoute']);
demoApp.config(function ($routeProvider) {
Define Module
$routeProvider
Routes
.when('/',
{
controller: 'SimpleController',
templateUrl:'View1.html'
})
.when('/view2',
{
controller: 'SimpleController',
templateUrl:'View2.html'
})
.otherwise({ redirectTo: '/' });
});
Where do Views Go in a
Dynamically loaded views are injected into the
Page?
shell page as a module loads:
SPA Demo
http://www.myspa.com
<div ng-view></div>
OR
<ng-view></ng-view>
View1
Factory injected
into controller at
runtime
Module
Config
Routes
View
Directives
$scope
Controller
*Factory
Summary
AngularJS provides a robust "SPA" framework for
building robust client-centric applications
Key features:
Thank you!
@DanWahlin
weblogs.asp.net/dwahlin
www.linkedin.com/pub/dan-wahlin/1/547/46b
Sample Code
http://tinyurl.com/AngularJSDemos
http://tinyurl.com/CustomerMgr