使用咕噜Angularjs微小丑化导致JS错误

使用咕噜Angularjs微小丑化导致JS错误

本文介绍了使用咕噜Angularjs微小丑化导致JS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在angularjs我们传递参数依赖注入。例如,

In angularjs we pass parameters as dependency injection. For example,

function checkInCtrl ($scope, $rootScope, $location, $http){
…..
….
}

因此​​,当它被缩小的,它变得像,

So when it gets minified, it becomes like,

function checkInCtrl(a,b,c,d){
}

现在A,B,C,D不会PTED为$范围,$ rootScope,$位置$通过角度和整个code分别HTTP无法工作间$ P $。对于此angularjs提供一种解决方案,这是

Now a,b,c,d won’t be interpreted as $scope, $rootScope, $location, $http respectively by angular and whole code fails to work. For this angularjs has provided one solution, which is

checkInCtrl.$inject = ['$scope', '$rootScope', $location', '$http'];

我们可以通过使用上述语法注入不同的依赖。这种运作良好,直到我没有使用一些自定义的角度服务为依赖。因此,例如,

we can inject different dependencies by using above syntax. This worked well till I didn’t use some custom angular service as dependency. So for example ,

如果我有像

function checkInCtrl ($scope, $rootScope, $location, $http){
…..
….
}

它与给出的解决方案,但如果我有像

It works with given solution, but if I have something like

function checkInCtrl ($scope, $rootScope, $location, $http, customService){
…..
….
}

在哪里customService是一样的东西。

Where customService is something like

angular.module(customService, ['ngResource'])
                .factory('abc', function($resource) {
                                return $resource('/abc');
                })

它的精缩版没有得到通过角正常PTED间$ P $。

It’s minified version doesn’t get interpreted properly by angular.

当我们不得不开始项目开发活动,我们不能花足够的时间来考虑此事,我们开始使用控制器没有污染减量他们。所以,第一个问题是,是否有这样的问题的角度还是我做了一些错误,因为它没有工作?如果这样的问题存在,有什么解决的办法?

As we had to start project development activities, we couldn’t spend enough time to look into matter and we started using controller without minifying them. So first question is whether there is such problem with angular or I made some mistake and due to which it didn't work? If such issue exist,what is solution to it?

推荐答案

您必须使用字符串注入基于语法,确保缩小的版本,分好依赖关系:

You have to use the string-injection based syntax that ensure that the minified version points to the good dependancy :

function checkInCtrl ($scope, $rootScope, $location, $http){}

变成了:

['$scope', '$rootScope', '$location', '$http', function checkInCtrl ($scope, $rootScope, $location, $http){}]

这篇关于使用咕噜Angularjs微小丑化导致JS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:20