Sudsy
unread,Apr 4, 2012, 3:23:02 AM4/4/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ang...@googlegroups.com
Hi There,
I am trying to separate my controllers into separate requirejs module files to assist with maintainability of my project.
I have got most of it working except for the controllers. I noticed that there is a $controllerProvider service that has a register function to allow the registration of modules and I have been trying this method (code below) but I can't seem to get it to work.
At the end of the day I am looking for the cleanest way to have one controller per file and then each controller loaded by requirejs so if there is a much better way than I am attempting please let me know.
Each Controller file looks something like this
define([
"services/dependency"
], function () {
"use strict";
var controller = function ($scope, servicedependency) {
$scope.search = function () {
// some sort of search function here
}
};
controller.$inject = ['$scope', 'servicedependency'];
var $injector = angular.injector();
$injector.invoke(['$controllerProvider', function ($controllerProvider) {
// Register The Controller
$controllerProvider.register('MyCtrl', controller);
}]);
return controller;
});
This code gives me "unknown provider $controllerProviderProvider <- $controllerProvider" I get a similar error when trying to use $controller as an injected service instead.
Any suggestions?
Ben