How can I get the name of a service (or factory, provider, controller, directive...) from WITHIN the object? Eg
angular.module('app', []).controller('myCtrl', function() {
// how do I get the name 'myCtrl' here?
})
The obvious way is hard coding, but I want to avoid that
.service('myService', function() {
this.name = 'myService';
});
I guess this is a way, but I'm hoping to avoid it as I don't want to have to declare globals in my app
var myCtrlName = 'myCtrl';
angular.module('app', []).controller(myCtrlName, function() {
console.log(myCtrlName);
});
$routeProvider.when('/', {templateUrl:'views/main.html',controller: 'myCtrl',...}), which also relies on names, and is an accepted (indeed celebrated) pattern in Angular. Do you have another suggestion?