javascript - Using Angular constant to declare controller names -
i trying declare constants string values use in angular project. sample code looks below,
//create module var myapp = angular.module("myapp",[]); //define constants controller names myapp.constant("controllers", { "login_controller" : "loginctrl", "home_page_controller" : "homepagectrl" });
now, while creating controllers in respective controller files, use below code,
myapp.controller(controllers.login_controller, function(){.....});
when execute application, below error during loading of loginctrl.js file,
"uncaught referenceerror: controllers not defined"
am using angular constants in wrong way?
thanks.
angular constants can injected angular functions
directive('foo', function(controllers){});
they not usable outside injection.
are trying use constants because adverse leaving directive names strings? using strings fine because if directive name ever changed have bigger issues.
is there instead other problem trying solve using constants?
Comments
Post a Comment