Angular JS
Angular JS
What is AngularJS?
A
GitHub: https://github.com/angular/angular.js
MIT License
Uses
jQuery
jQuery 1.7.1
jQLite
or above
MVC
Model
The data
Controller
JavaScript
The behavior
Modifying / updating the models
View
The interface
How the data is presented to the user
HTML
Data Binding
Views
are declarative
Sample Application
GitHub:
https://github.com/christophertfoo/AngularSa
mple
Views
ng-app
ng-controller
ng-model
Views
More
ng directives
ng-if=<model expression>
ng-repeat=<variable> in <array>
Views
{{
}}
Angular expressions
Controller
Function is a constructor
Ex:
function MyCtrl($scope) { }
$scope
JavaScript object
Contains data (i.e. models) and methods (i.e. functions)
Can add own properties
Controller
Dependency Injection
$http
Controller
Typically
angular.module(<name>, [<dependencies>]);
Models
Properties
object
Standard JavaScript values
Modules
Can
Modules
var myControllers =
angular.module(myControllers, []);
// Add controllers to the module
myControllers.controller();
var myApp = angular.module(myApp,
[myControllers]);
More
Custom directives
Filters
http://docs.angularjs.org/guide/directive
http://docs.angularjs.org/guide/dev_guide.templates.filte
rs
To learn more:
Tutorial: http://docs.angularjs.org/tutorial
Documentation:
http://docs.angularjs.org/guide/overview
/ Comments?
Routing
Use
part of a page)
Used in conjunction with the ng-view directive
Routing
$routeProvider.when(<path>, {<route>});
/user/:userId
$routeProvider.otherwise({<route>});
redirectTo: <path>
API: http://docs.angularjs.org/api/ngRoute.$routeProvider
Routing
URL
parameters
$routeParams service
The $routeParams object will have a field with
the same name as the parameter
Ex.
$routeParams.userId
Routing
Example URL.
http://www.mysite.com/#/users
Ex.
Example URL:
http://www.mysite.com/users