Say I have a controller:
app.controller('HomeCtrl', Com.Xyz.ModuleHome.HomeController);
Com.Xyz.ModuleHome.HomeController is a controller function which has parameters like $scope, $window, $timeout, $http, ... these parameters are injected by AngularJS.
But I want to pass some parameters to the controller when it is registered. This is because my controllers are loaded from different domains by RequireJS, now I want to a controller to know where itself is from.
var myVar = jsFileUrl; // jsFileUrl is provided by RequireJS
// I wish the code looks like below
app.controller('HomeCtrl', Com.Xyz.ModuleHome.HomeController, myVar);
// AngularJS will inject a $controllerContext representing controller itself
function Com.Xyz.ModuleHome.HomeController($controllerContext, $scope) {
$scope.controllerJsFileUrl = $controllerContext.Argument;
}
Is it possible? Maybe there is something I didn't know.
I know a service can do it, but I don't want the controller to depend on a special service name. In the future I may move the controllers to somewhereelse.