I have controller defined as this:
var servicesInstance = angular.module('myApp');
servicesInstance.controller('ServicesViewController', function() {
console.log("ServicesViewControllerconstructor.");
this.initialize = function() {
console.log("ServicesViewController initialize.");
};
});
And I would like to get an instance of it dynamically in code like this:
var instance = $injector.get('ServicesViewController');
Note: please ignore the hardcoded strings. For this post, I hardcoded the strings. however, in reality, the controller name will come from configuration data (eg: json object).
The instance variable is always null. $injector.has('ServicesViewController') always returns false.
Why would this be the case? Is this the correct way to get a controller instance?
Thank you Matt
EDIT: Throwing in more info I kept out because I was trying to keep the question simple. I am using requireJS to load the javascript code which creates the controller. EG:
define([], function(ServicesViewControllerProvider) {
'use strict';
var servicesInstance = angular.module('myApp');
servicesInstance.controller('ServicesViewController', function() {
console.log("ServicesViewController Constructor");
this.initialize = function() {
console.log("ServicesViewController initialize.");
};
});
var servicesViewController = new Object();
servicesViewController.$inject=['$scope'];
servicesViewController.view = "/test/ServicesView.html";
servicesViewController.requiresUI = true;
servicesViewController.controllerName = "ServicesViewController";
return servicesViewController;
});
Thanks Matt