KEMBAR78
CFUGbe talk about Angular JS | PDF
ANGULAR JS 
COLDFUSION USER GROUP MEETING 
Presentation by Alwyn Wymeersch / @alwynW
WHO'S THIS GUY? 
ALWYN WYMEERSCH 
Freelance webdeveloper & instructor 
Flames Productions
HOW DID I GET TO ANGULAR?
BACKBONE JS 
more OOP approach
LET'S TRY SOMETHING NEW!
HEY... IT'S GOOGLE WHAT DID YOU EXPECT?
THE BASICS
MODEL DRIVEN
Extend html with ng-tags 
ng-app 
ng-model 
ng-repeat 
... 
Bind content with {{}}
DEFINE APP 
angular.module('name', [dependencies]); 
* dependencies: other modules, libraries, everything that’s not 
‘core’ (animation, routing, ext libs) 
var myApp = angular.module('myApp', ['ngRoute','ngAnimate']);
DEFINE CONTROLLER 
module.controller('name', function(depencies){}); 
var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, $location){ 
// Code goes here 
});
or... 
module.controller('name', [dependencies, 
function(injected dependencies){ 
}); 
var app = angular.module('myApp', []); 
app.controller('myCtrl', ['$scope', '$location', function($scope, $location){ 
}]); 
code obfuscation
ROUTING 
MULTI-VIEW APPS
Navigation through location change 
1. Change url (#) 
2. app maps view with ctrl 
3. wait for optional dependencies 
4. view loaded in ng-view container 
5. optional animation(s) 
Configured in app config via $routeprovider
ROUTEPROVIDER 
var myApp = angular.module('myApp',['ngRoute']); 
myApp.config(['$routeProvider', function ($routeProvider){ 
$routeProvider.when("home", { 
url: "/", 
controller: "HomeController", 
templateUrl: "app/views/HomeView.html" 
}) 
.when("register", { 
controller: "RegisterController", 
templateUrl: "app/views/RegisterView.html" 
}) 
.otherwise('/'); 
});
NESTED VIEWS? 
Use ui-router
SHARE DATA BETWEEN CONTROLLERS 
Service or Factory 
Injectable 
Single instance
SERVICE 
module.service('name', [dependencies, 
function(injected dependencies){ 
// Instance variables and functions 
}); 
var app = angular.module('myApp', []); 
app.service('RegistrationModel', [ function(){ 
this.registrations = []; 
this.getRegistrations = function(){ 
// go fetch 
} 
}]);
FACTORY 
module.factory('name', [dependencies, 
function(injected dependencies){ 
// Return object with variables and functions 
}); 
var app = angular.module('myApp', []); 
app.factory('RegistrationModel', [ function(){ 
var model = {}; 
model.registrations = []; 
model.getRegistrations = function(){ 
// go fetch 
} 
return model; 
}]);
INJECT SERVICES / FACTORY 
var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope, RegistrationModel){ 
$scope.registrations = RegistrationModel.registrations 
});
GETTING EXTERNAL DATA 
Any source that outputs json format 
$http service 
promises
QUESTIONS? 
ALWYN@FLAMESPRODUCTIONS.COM

CFUGbe talk about Angular JS

  • 1.
    ANGULAR JS COLDFUSIONUSER GROUP MEETING Presentation by Alwyn Wymeersch / @alwynW
  • 2.
    WHO'S THIS GUY? ALWYN WYMEERSCH Freelance webdeveloper & instructor Flames Productions
  • 3.
    HOW DID IGET TO ANGULAR?
  • 4.
    BACKBONE JS moreOOP approach
  • 5.
  • 7.
    HEY... IT'S GOOGLEWHAT DID YOU EXPECT?
  • 8.
  • 9.
  • 10.
    Extend html withng-tags ng-app ng-model ng-repeat ... Bind content with {{}}
  • 11.
    DEFINE APP angular.module('name',[dependencies]); * dependencies: other modules, libraries, everything that’s not ‘core’ (animation, routing, ext libs) var myApp = angular.module('myApp', ['ngRoute','ngAnimate']);
  • 12.
    DEFINE CONTROLLER module.controller('name',function(depencies){}); var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $location){ // Code goes here });
  • 13.
    or... module.controller('name', [dependencies, function(injected dependencies){ }); var app = angular.module('myApp', []); app.controller('myCtrl', ['$scope', '$location', function($scope, $location){ }]); code obfuscation
  • 14.
  • 15.
    Navigation through locationchange 1. Change url (#) 2. app maps view with ctrl 3. wait for optional dependencies 4. view loaded in ng-view container 5. optional animation(s) Configured in app config via $routeprovider
  • 16.
    ROUTEPROVIDER var myApp= angular.module('myApp',['ngRoute']); myApp.config(['$routeProvider', function ($routeProvider){ $routeProvider.when("home", { url: "/", controller: "HomeController", templateUrl: "app/views/HomeView.html" }) .when("register", { controller: "RegisterController", templateUrl: "app/views/RegisterView.html" }) .otherwise('/'); });
  • 17.
  • 18.
    SHARE DATA BETWEENCONTROLLERS Service or Factory Injectable Single instance
  • 19.
    SERVICE module.service('name', [dependencies, function(injected dependencies){ // Instance variables and functions }); var app = angular.module('myApp', []); app.service('RegistrationModel', [ function(){ this.registrations = []; this.getRegistrations = function(){ // go fetch } }]);
  • 20.
    FACTORY module.factory('name', [dependencies, function(injected dependencies){ // Return object with variables and functions }); var app = angular.module('myApp', []); app.factory('RegistrationModel', [ function(){ var model = {}; model.registrations = []; model.getRegistrations = function(){ // go fetch } return model; }]);
  • 21.
    INJECT SERVICES /FACTORY var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, RegistrationModel){ $scope.registrations = RegistrationModel.registrations });
  • 22.
    GETTING EXTERNAL DATA Any source that outputs json format $http service promises
  • 23.