I am still very new to AngularJS and am working on customizing my first application. I would like to be able to do the following:
angular.module('App.controllers', []) .controller('home', function () { $scope.property = true; }]); angular.module('App', ['App.controllers']) .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/', {templateUrl: 'partials/home.html', controller: home}); }]);
Using this setting, the following error is generated:
Uncaught ReferenceError: home is not defined from App
My question is: how can I register controllers using angular.module.controller() (or $controllerProvider.register() directly) and use the registered controller elsewhere in my application.
My motivation: I would like to avoid using global constructor functions as my controllers (like most examples of using angularjs.org) or a complex namespace. If I can register and use controllers as the names of individual variables (which then do not fit in the global scope), that would be ideal.
angularjs
Noah Freitas Jun 26 '12 at 16:38 2012-06-26 16:38
source share