AngularJS Service Config value get destroyed on minification

后端 未结 3 1695
情话喂你
情话喂你 2021-01-11 11:02

Having some trouble with minification and AngularJS ;-(

I found this jsfiddle \"loading\" extender for HTTP request, through the AngularJS Wiki page.

It work

3条回答
  •  梦谈多话
    2021-01-11 11:22

    Just for others in the same situation... I followed @Stewie 's advice, and made this instead, which only uses AngularJS code, no stupid jQuery dependency ;-)

    Service:

    app.config([
      "$httpProvider", function($httpProvider) {
        var spinnerFunction;
        $httpProvider.responseInterceptors.push("myHttpInterceptor");
        spinnerFunction = function(data, headersGetter) {
          return data;
        };
        return $httpProvider.defaults.transformRequest.push(spinnerFunction);
      }
    ]).factory("myHttpInterceptor", [
      "$q", "$window", "$rootScope", function($q, $window, $rootScope) {
        return function(promise) {
          $rootScope.$broadcast("loader_show");
          return promise.then((function(response) {
            $rootScope.$broadcast("loader_hide");
            return response;
          }), function(response) {
            $rootScope.$broadcast("loader_hide");
            $rootScope.network_error = true;
            return $q.reject(response);
          });
        };
      }
    ]);
    

    Directive

    app.directive("spinner", function() {
      return function($scope, element, attrs) {
        $scope.$on("loader_show", function() {
          return element.removeClass("hide");
        });
        return $scope.$on("loader_hide", function() {
          return element.addClass("hide");
        });
      };
    });
    

提交回复
热议问题