Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 防止$httpProvider拦截器在模板加载时触发_Javascript_Angularjs_Angular Promise - Fatal编程技术网

Javascript 防止$httpProvider拦截器在模板加载时触发

Javascript 防止$httpProvider拦截器在模板加载时触发,javascript,angularjs,angular-promise,Javascript,Angularjs,Angular Promise,想要一个简单的拦截器,每200个状态触发一个日志记录方法。这很容易设置,但现在我注意到我所有的Angle模板都是通过$httpProvider加载的,因此触发了我的200拦截器。有没有办法区分模板加载和实际API调用 $httpProvider.interceptors.push(function() { return { response: function(response) { if(response.status ===

想要一个简单的拦截器,每200个状态触发一个日志记录方法。这很容易设置,但现在我注意到我所有的Angle模板都是通过$httpProvider加载的,因此触发了我的200拦截器。有没有办法区分模板加载和实际API调用

  $httpProvider.interceptors.push(function() {
      return {
          response: function(response) {

              if(response.status === 200) console.log(response);
              return response;
          }
      };
  });

对。你可以。在响应对象中,有一个配置对象,在配置对象中是您请求的资源的URL。所以

  $httpProvider.interceptors.push(function() {
      return {
          response: function(response) {

              if(response.status === 200) console.log(response);
              return response;
          }
      };
  });
 $httpProvider.interceptors.push(function() {
      return {
          response: function(response) {

                function endsWith  ( str, suffix ) {
                    return str.indexOf(suffix, str.length - suffix.length) !== -1;
                }

              if(response.status === 200 && !endsWith( response.config.url, '.html') ) console.log(response);
              return response;
          }
      };
  });