I am working on setting up configuration files in AngularJS. Is it possible to create a factory in AngularJS whose key cannot be overwritten? For example, I can configure a constant that cannot be overwritten
module.constant ('animals', {"cat": "meow", "dog": "woof"});
But I would like to do something similar that allows overwriting the values, but not the factory itself
module.value('catSound','meow') .value('dogSound','woof') .factory('animals', ['catSound','dogSound', function(catSound, dogSound) { return { "cat": catSound, "dog": dogSound } });
The aforementioned factory can be overwritten if another piece of code has module.factory('animals',function(){ return 7 }) and breaks everything. However, as a factory, individual values ββcan (and should) be writable, so I should be able to assign module.value('catSound','hiss') and still work as expected.
I tried to inject into constants, but as far as I could understand, this is impossible. How can I prevent rewriting of a factory declaration? I understand that a constant is probably not the right term when describing what I want, but I want the definition of the factory function to be constant.
Ian hunter
source share