I have defined a constant like this:
app.constant('ngSettings', {
apiBaseUrl: 'https://url/'
});
how can I reference now this constant in a directive?
Where the directive is something like this:
angular.module('my.directive', []).directive(...................
You can inject the constant anywhere that is injectable including the directive definition itself, the controller of a directive, the link function, et. al.
angular.module('my.directive', []).directive('name', ['ngSettings', function (ngSettings) {
// do things with ngSettings
return {};
}]);
By the way I wouldn't name anything you define yourself as ng
-- that should be preserved for things in the ng
module or that Angular itself created.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With