Ondrej Svejdar Ondrej Svejdar - 3 months ago 10x
AngularJS Question

Override $templateCache to be case insensitive

Can one override core provider like

while maintaining reference to the original provider ?
I'd like to override
to be case insensitive.

I.E. something like

var normalGet = $templateCache.get;
var normalPut = $templateCache.put;
$templateCache.get = function(key) { normalGet(key.toLowerCase()); };
$templateCache.put = function(key,value) { normalPut(key.toLowerCase(), value); };

But less hacky, more DI-style ?


I'd say use decorator to modify the actual Provider code which will be done at configuration phase before coming into action.

We used $templateCacheProvider because Provider appended prefix indicate that its provider(it can be Directive when you are modifying directive DDO of directive). You have to place this code inside config phase of your application.


app.config(['$provide', Decorate]);
function Decorate($provide) {
    ['$delegate', function($delegate) {
      var templateCache = $delegate[0];

      var normalGet = templateCache.get;
      var normalPut = templateCache.put;
      templateCache.get = function(key) { normalGet(key.toLowerCase()); };
      templateCache.put = function(key,value) { normalPut(key.toLowerCase(), value); };

      return $delegate;