-2

I am a beginner in angular..I have a requirement to avoid hard coding any names in the app.. I have used

myapp.constant("constantName",
{
    "name":"name1"
});

to avoid hard coding html..I would also like to avoid hard coding controller names also...

example :

myapp.controller("IndexCtrl",function($scope){});

Instead of having the string IndexCtrl in the controller, is there any way to define something like this

myapp.controller(constantName.controller,function($scope){})

where the constant will be

myapp.constant("constantName",
{
    "name":"name1",
    "controller" : "IndexCtrl"
});

Thanks for the help :)

Skwal
  • 2,160
  • 2
  • 20
  • 30

1 Answers1

1

I have not seen anything quite like that before, but what I have seen (and done) is define your controller like so:

(function(){
    var controllerName = 'MyCtrl';
    angular.module('myModule').controller(controllerName, function($scope, $log){
        // Now in my controller I have full access the controller name 
        // this can be used for any logging that I may need to do
        $log.debug('something broke in ' + controllerName);
    });
})();
Brocco
  • 62,737
  • 12
  • 70
  • 76