Skip to content

Instantly share code, notes, and snippets.

@Ollo
Created October 8, 2014 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ollo/c21c8ff32c59d728c462 to your computer and use it in GitHub Desktop.
Save Ollo/c21c8ff32c59d728c462 to your computer and use it in GitHub Desktop.
angular module pattern example
// user-profile-controller.js
define([
'angular',
'components/userProfile/user-profile-factory.js',
'components/userProfile/user-profile-directives.js',
],
function(){
'use strict';
var module = angular.module('userProfile.module', ['userProfile.directives', 'userProfile.factory']);
module.controller('userProfileController', ['$scope', 'userProfileDirectives', 'userProfileFactory', function($scope, userProfileDirectives, userProfileFactory){
$scope.userfunctionthings() {
...
}
}]);
});
// user-profile-directives.js
define([
'angular',
'common/other-directive'
],
function(){
'use strict';
var module = angular.module('userProfile.directives' ['common.other-directive']);
module.directive('userProfileNav', [ function(){
return {
// directive definition
...
};
}]);
});
// user-profile-factory.js
define([
'angular',
'ng-resource'
],
function(){
'use strict';
var module = angular.module('userProfile.factory', ['ngResource']);
var module.factory('userProfileFactory', ['$resource', function($resource){
return {
getUser: function() {
return $resource('api/user/:id', {id: '@id'});
}
};
}]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment