6. Different approach to web app architecture.
Boiler plate and cruft replaced with black magic and voodoo.
But seriously- it is a different approach.
Apps, Controllers, Directives, Services
7. Apps (modules)
You’ll probably only have one
Essential building block
var heroes = angular.module('heroes', []);
It’s your namespace
8. Controllers
If the HTML is the where and the JS is the what…
controllers are the how…
Most importantly- they give you a scope.
(and lots of other stuff)
heroes.controller('HeroController', ['$scope',
function($scope){
$scope.hero = 'Spiderman';
}]);
9. Directives
This is really the where- they are used in the HTML
Encapsulate logical functionality and display
Can have templates
Can have controllers
Can have an isolated scope
10. Services
There are providers, services, and factories
Let’s focus on factory
heroes.factory('HeroFactory', function(){
return function(name) {
return {
name: name,
superpower: null,
alterEgo: null
}
}
});