Skip to content

Instantly share code, notes, and snippets.

@thomastuts
Created September 26, 2013 17:03
Show Gist options
  • Save thomastuts/6717157 to your computer and use it in GitHub Desktop.
Save thomastuts/6717157 to your computer and use it in GitHub Desktop.
AngularJS code convention: 2 ways of declaring controllers
/**
* WAY 1: ANGULARJS TUTORIAL
*/
// app.js
var myApp = angular.module('myApp',[]);
// controllers/greeting.js
myApp.controller('GreetingCtrl', ['$scope', function($scope) {
$scope.greeting = 'Hola!';
}]);
/**
* WAY 2: THINKSTER.IO FANTASY FOOTBALL
*/
//app.js
window.app = angular.module('ngFantasyFootball', [
'ngCookies', 'ngResource', 'ui.bootstrap', 'ngRoute', 'ngff.controllers', 'ngff.directives', 'ngff.services'
]);
window.angular.module('ngff.controllers', [
'ngff.controllers.header',
'ngff.controllers.index',
'ngff.controllers.nfl',
'ngff.controllers.leagues',
'ngff.controllers.fantasyteams'
]);
window.angular.module('ngff.services', [
'ngff.services.global',
'ngff.services.nfl',
'ngff.services.leagues',
'ngff.services.fantasyteams'
]);
// controllers/fantasyteams.js
window.angular.module('ngff.controllers.fantasyteams', [])
.controller('FantasyTeamsController', ['$scope', '$routeParams', '$location', 'Global', 'Leagues', 'FantasyTeams',
function ($scope, $routeParams, $location, Global, Leagues, FantasyTeams) {
$scope.global = Global;
$scope.populateLeagues = function (query) {
Leagues.query(query, function (leagues) {
$scope.leagues = leagues;
})
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment