5

I was trying to avoid template errors with angular js when my user became unauthenticated. To do this, I came to this stackoverflow solution.

It worked for me, but now I noticed that my ng-animate stopped working without throwing console errors.

What am I missing?

Update: This is the code used

var app = angular.module('app',[]);

app.config(['$provide', function($provide) {
  $provide.decorator('$templateRequest', ['$delegate', function($delegate) {
    var mySilentProvider = function(tpl, ignoreRequestError) {
      return $delegate(tpl, true);
    }
    return mySilentProvider;
  }]);
}]);
Community
  • 1
  • 1
William Weckl
  • 2,435
  • 4
  • 26
  • 43

1 Answers1

4

The function $templateRequest contains additional properties that are used internally. You need to move these properties to the new function.

Here is an implementation that should work:

app.config(['$provide', function($provide) {
  $provide.decorator('$templateRequest', ['$delegate', function($delegate) {

    var fn = $delegate;

    $delegate = function(tpl) {

      for (var key in fn) {
        $delegate[key] = fn[key];
      }

      return fn.apply(this, [tpl, true]);
    };

    return $delegate;
  }]);
}]);
tasseKATT
  • 38,470
  • 8
  • 84
  • 65
  • 2
    I had the same problem, but this didn't quite fix it. you need to move the for loop to be outside the actual function call, as otherwise it won't copy everything over until you've requested your first template. – M21B8 Jun 17 '16 at 15:17