--
- A framework?
- A library?
- A plugin?
--
- A Javascript toolset
- Extends HTML
- Allows you to create Single Page Applications
--
- Javascript and HTML are flawed by themselves
- Demand for the Client to do the heavy lifting
- Testing Client side code is difficult
- Client side tools/libraries are disparate
- SPA's are complex
--
- Two way data bindings
- Dependency Injection
- Testability
- Modularity
- Promises
--
- Karma test runner for unit tests
- Protractor for End to End tests
- Batarang Chrome debugger plugin
--
- Download the JS file from angularjs.org
- Clone it from GitHub
- Bootstrap it using Yeoman
- Use a Mean stack e.g. mean.io
<div ng-app></div>
--
- Controllers provide the business logic for the view
- They can inherit from other controllers
- They define what the scope for a view is
--
function PhoneListCtrl($scope) {
$scope.phones = [
{"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S."},
{"name": "Motorola XOOM™ with Wi-Fi",
"snippet": "The Next, Next Generation tablet."},
{"name": "MOTOROLA XOOM™",
"snippet": "The Next, Next Generation tablet."}
];
}
--
var myApp = angular.module('myApp', []);
myApp.controller('PhoneListCtrl', PhoneListCtrl);
Initialise your App by declaring your new module
<div ng-app="myApp"></div>
- Modules can list other modules as their dependencies
--
var myApp = angular.module('myApp', []);
myApp.controller('PhoneListCtrl', function($scope) {
$scope.phones = [
{'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'},
{'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'},
{'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.'}
];
});
--
A controller can be linked to a view by using ng-controller
<div ng-controller="myController"></div>
--
Or by defining it in a route for your App (using ng-view)
<div ng-view></div>
angular.module('myApp').
config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/my-page', {
templateUrl : 'views/myPage.html',
controller : 'myController'
})
})
--
The Scope binds the Model and the View together
- It is the context of the model
- They can inherit
- Directives can create their own scope
- Whenever the scope changes the view is updated
--
A view is An HTML file or template presented to the user
- Where you declare what directives you want to use
- HTML combined with Angular expressions
- Automatic dirty checking in forms avoids model get and set
- Can often tell you exactly what is meant to be happening
--
Calling a function on scope
<div ng-click="doSomething()"></div>
Displaying a variable in the view
<div ng-bind="myVariable"></div>
<div>{{myVariable}}</div>
--
Displaying our list of phones
<ul>
<li ng-repeat="phone in phones">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
--
- A task that can be realised entirely in the view
<div ng-class="{toggleOn: toggle}">Item</div>
<a ng-click="toggle=!toggle">Toggle</a>
- Note, if a scope variable doesn't exist Angular will create it
--
A piece of code that accomplishes a specific task
- Handles the behaviour of the UI
- Helps to eliminate Javascript specific CSS
- Allows for effective reusable components
- Fully testable
- Perfect for validation
--
- Directives are great at describing the UI
- TDD is accessible on the client side
- Acceptance testing with Protractor makes life better
- Module pattern and inheritance is effective
- Inherited scope is not easy
- Directives can take a bit of learning
--
- angularjs.org
- ng-conf.org
- yearofmoo.com
- github.com/angular/angular.js
- ng-newsletter.com
--