AngularJS in 60ish Minutes
Dan Wahlin
Blog
http://weblogs.asp.net/dwahlin
Twitter
@DanWahlin
Win a free copy of the video course!
More details at:
http://tinyurl.com/AngularJSJumpStart
http://angularjs.org
Agenda
 AngularJS Features
 Getting Started
 Directives, Filters and Data Binding
 Views, Controllers and Scope
 Modules, Routes and Factories
Getting Started
Single Page Application (SPA)
SPA Demo
http://www.myspa.com
View View
View View
The Challenge with SPAs
DOM Manipulation History
Routing
Module Loading
Data Binding
Object Modeling
Ajax/Promises
Caching
View Loading
ngularJS is a full-featured
SPA framework
Data Binding MVC Routing
Templates
ViewModel Views
Controllers Dependency Injection
Directives
Testing
Controllers
jqLite
Validation
FactoriesHistory
Directives, Filters
and Data Binding
What are Directives?
They teach HTML new tricks!
<!DOCTYPE html>
<html ng-app>
<head>
<title></title>
</head>
<body>
<div class="container">
Name: <input type="text" ng-model="name" /> {{ name }}
</div>
<script src="Scripts/angular.js"></script>
</body>
</html>
Directive
Directive
Data Binding
Expression
Using Directives and Data Binding Syntax
<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
Iterating with the ng-repeat Directive
AngularJS Help for Directives
<ul>
<li data-ng-repeat="cust in customers | orderBy:'name'">
{{ cust.name | uppercase }}
</li>
</ul>
Order customers by
name property
<input type="text" data-ng-model="nameText" />
<ul>
<li data-ng-repeat="cust in customers | filter:nameText |
orderBy:'name'">
{{ cust.name }} - {{ cust.city }}</li>
</ul>
Filter customers by
model value
Using Filters
AngularJS Help for Filters
Demo
Views, Controllers
and Scope
View Controller$scope
$scope is the "glue" (ViewModel)
between a controller and a view
View, Controllers and Scope
<div class="container" data-ng-controller="SimpleController">
<h3>Adding a Simple Controller</h3>
<ul>
<li data-ng-repeat="cust in customers">
{{ cust.name }} - {{ cust.city }}
</li>
</ul>
</div>
<script>
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>
Define the
controller to use
Basic controller
$scope injected
dynamically
Access $scope
Creating a View and Controller
Demo
Modules, Routes
and Factories
View Controller
*FactoryDirectives
Routes
Module
Config
$scope
ControllerFactoryDirective
Routes
Module
Config
Service
Provider
<html ng-app="moduleName">
Modules are Containers
Value
Filter
var demoApp = angular.module('demoApp', []);
What's the
Array for?
var demoApp = angular.module('demoApp',
['helperModule']);
Module that demoApp
depends on
Creating a Module
var demoApp = angular.module('demoApp', []);
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' }
];
});
Define a Module
Define a Controller
Creating a Controller in a Module
The Role of Routes
SPA Demo
http://www.myspa.com
View1 View2
View4 View3
/view2
/view3
/view4
/view1
Defining Routes
var demoApp = angular.module('demoApp', ['ngRoute']);
demoApp.config(function ($routeProvider) {
$routeProvider
.when('/',
{
controller: 'SimpleController',
templateUrl:'View1.html'
})
.when('/partial2',
{
controller: 'SimpleController',
templateUrl:'View2.html'
})
.otherwise({ redirectTo: '/' });
});
Define Module
Routes
SPA Demo
http://www.myspa.com
Where do Views Go in a Page?
Dynamically loaded views are injected into the
shell page as a module loads:
<div ng-view></div>
<ng-view></ng-view>
OR
View1
The Role of Factories
var demoApp = angular.module('demoApp', [])
.factory('simpleFactory', function () {
var factory = {};
var customers = [ ... ];
factory.getCustomers = function () {
return customers;
};
return factory;
})
.controller('SimpleController', function ($scope,
simpleFactory) {
$scope.customers = simpleFactory.getCustomers();
});
Factory injected into
controller at runtime
View Controller
*FactoryDirectives
Routes
Module
Config
$scope
Demo
Summary
 AngularJS provides a robust "SPA" framework
for building robust client-centric applications
 Key features:
 Directives and filters
 Two-way data binding
 Views, Controllers, Scope
 Modules and Routes
Sample Code
http://tinyurl.com/AngularJSDemos
http://tinyurl.com/CustomerMgr
Win a free copy of the video course!
More details at:
http://tinyurl.com/AngularJSJumpStart
Newsletter and FlipBoard Magazines
http://weblogs.asp.net/dwahlin
Dan Wahlin
Blog
http://weblogs.asp.net/dwahlin
Twitter
@DanWahlin

AngularJS in 60ish Minutes

Editor's Notes

  • #6 First time I looked at it I felt like it was a little strange….but I could go with it.
  • #7 As I researched more I came across some things that looked really strange and just didn&apos;t click with me.
  • #8 I saw a lot of words that were confusing and after more research I started to get a little frustrated…kind of felt like this kid.
  • #9 But, I stuck with it, kept on researching and playing around with the samples,took a deep breath and….
  • #10 I chilled out, and once a few things started to click I started to realize that I could really take advantage of some great features!
  • #11 Once you have that &quot;light bulb moment&quot; you realize how powerful and flexible AngularJS is. That&apos;s when it truly changes how you think about writing Single Page Applications (SPAs) and client-side applications in general.
  • #12 And then at some point it hit me – this framework is really powerful!