I\'ve got an app defined this way:
angular.module(\"myApp\", [...])
.config(function ($stateProvider, $controllerProvider) {
if (isControllerDefined(co
An example of a service that can check if a controller exists. Note that it looks for a global function with specified name as well as a controller in the $controller
provider.
angular.service('ControllerChecker', ['$controller', function($controller) {
return {
exists: function(controllerName) {
if(typeof window[controllerName] == 'function') {
return true;
}
try {
$controller(controllerName);
return true;
} catch (error) {
return !(error instanceof TypeError);
}
}
};
}]);
See the fiddle for usage.