How to avoid $compile:tpload errors on 401 status code response

后端 未结 3 922
抹茶落季
抹茶落季 2021-02-02 15:58

We are developing a Single Page Application with AngularJS and ASP.NET MVC Json Rest API.

When an unauthenticated client tries to navigate to a private route (Ex: /F

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-02 16:14

    After some thinking I remembered about decorating in Angular, it solved this problem perfectly:

    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;
      }]);
    }]);
    

提交回复
热议问题