Joe Buza
Framework that allows you to create dynamic single web applications that are "extraordinary expressive, readable and quick to develop”
Design pattern that deals with how components get a hold of dependencies.
" The Angular injector subsystem is in charge of creating components, resolving their dependencies, and providing them to other components as requested."
var myApp = angular.module('myApp', []);
myApp.controller('MyController', ['$scope','Logger',function($scope, Logger) {
$scope.hello = "Hello";
$scope.world = "World";
$scope.alert = function(arg){
alert(arg);
}
Logger.log($scope.hello);
}]);
eg. $scope and Logger are dependencies
Angular Modules register:
// myApp module is used to register the different components of my app
// The components include: controller, factory, directive, filter
var myApp = angular.module('myApp', []);
// CONTROLLER
myApp.controller('MyController', ['$scope', 'postfixFilter', '$filter', function($scope, postfixFilter, $filter) {
$scope.hello = "Hello";
$scope.world = "World";
$scope.alert = function(arg) {
alert(arg);
}
// Options 1: Note: Have to append "Filter" to the filter name:
var psFx1 = postfixFilter($scope.hello,'--FILTER');
// Option 2: Use $filter
var psFx2 = $filter('postfix')($scope.hello,'--FILTER');
}]);
// SERVICE
myApp.factory('Logger', ['$log',function($log) {
return {
log: log
};
function log(data) {
$log.info(data);
}
}]);
// DIRECTIVE
myApp.directive("helloWorld", [function() {
return {
restrict: 'EA',
template: "<h1>Hello World</h1>"
};
}]);
// FILTER
myApp.filter('postfix', ['Logger', function(Logger) {
return function(input, post) {
Logger.log(post);
if (!post) {
return input;
}
return input += post;
}
}]);
var myApp = angular.module('myApp', []);
myApp.controller('MyController', ['$scope','Logger',function($scope, Logger) {
$scope.hello = "Hello";
$scope.world = "World";
$scope.alert = function(arg){
alert(arg);
}
Logger.log($scope.hello);
}]);
<div ng-app='myApp'>
<div ng-controller="MyController">
<!-- Scope Data -->
<div>{{hello}} {{world}}</div>
<!-- Scope Function -->
<button ng-click='alert("Clicked")'>Click Me!</button>
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.controller('MyController', ['$scope','Logger',function($scope, Logger) {
$scope.hello = "Hello";
$scope.world = "World";
$scope.alert = function(arg){
alert(arg);
}
Logger.log($scope.hello);
}]);
<div ng-app='myApp'>
<!-- CONTROLLER -->
<div ng-controller="MyController">
</div>
</div>
var myApp = angular.module('myApp', []);
myApp.factory('Logger', ['$log',function($log) {
return {
log: log
};
function log(data) {
$log.info(data);
}
}]);
// Service "Logger" Injected In Controller
myApp.controller('MyController', ['$scope','Logger',function($scope, Logger) {
Logger.log($scope.hello);
}]);
eg. ng-show, ng-hide, ng-class, ng-click
var myApp = angular.module('myApp', [])
myApp.directive("helloWorld", [function() {
return {
restrict: 'EA',
template: "<h1>Hello World</h1>"
};
}]);
<div ng-app='myApp'>
<hello-world></hello-world>
</div>
var myApp = angular.module('myApp', [])
myApp.filter('postfix', ['Logger', function(Logger) {
return function(input, post) {
Logger.log(post);
if (!post) {
return input;
}
return input += post;
}
}]);
//View Template
<div ng-app='myApp'>
<div ng-controller="MyController">
<!-- Filter -->
<div>{{ hello | postfix:'--FILTER'}}</div>
</div>
</div>
// Inside Controller
myApp.controller('MyController', ['$scope', 'postfixFilter', '$filter', function($scope, postfixFilter, $filter) {
$scope.hello = "Hello";
$scope.world = "World";
$scope.alert = function(arg) {
alert(arg);
}
// Options 1: Note: Have to append "Filter" to the filter name:
var psFx1 = postfixFilter($scope.hello,'--FILTER');
// Option 2: Use $filter
var psFx2 = $filter('postfix')($scope.hello,'--FILTER');
}]);
Extends HTML making your page expressive
Quick prototyping
Easy to test due to Dependency injection.
Two way data binding
Dependency injection
Funded by google
Steep learning curve once you get the basics
Organizing big projects
Hard to debug scopes
Directives are powerful but complex. Sometimes having multiple directives can cause errors
Apps can run slow if you watch deep object graphs