JS缩小,Heroku和jQuery.parseJSON [英] JS minification, Heroku and jQuery.parseJSON

查看:135
本文介绍了JS缩小,Heroku和jQuery.parseJSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚钻进去对我的web应用程序错误。

I just dig into an error on my web app. It's running with Rails 3 and AngularJS and when the web app deployed on Heroku, I had this error :

Unknown provider: tProvider <- t

我找到了一些办法#2关于微小的问题,然后再深入点出线(S)。
然后,测试之后,我发现它和惊讶:

I found some ways on Stackoverflow about minification issues and then go deeper to point out the line(s). Then after tests I found it and was surprised :

 $scope.list = jQuery.parseJSON(list_json);

list_json 是在DATAS DIV即暂时放养。这种运作良好,对当地。
任何想法,为什么 jQuery.parseJSON 是创建这个错误?有没有解决办法?

list_jsonis datas stocked temporarly in div. This works well on local. Any idea why jQuery.parseJSON is creating this error ? Is there a workaround ?

推荐答案

如果你不使用缩小的JS在你的地方,这可以解释的差异。如果您在微小的工作原理看一点点,你会看到你的依赖都变成了变量的名称,如 A B 来使他们的迷你儿。所以角不知道你指的是什么了。有几个方式来处理这个问题:

If you're not using minified JS on your local, that would explain the discrepancy. If you look a little bit at how minification works, you'll see that your Dependencies are turned into variable names like a and b to make them "mini-er". So Angular doesn't know what you're referring to anymore. There are a few ways to handle this:


  1. ngmin 是一个工具,可以自动完成这个和避免重复。

  2. 当你定义工厂,控制器,服务等,可以使用数组符号具有明确的变量命名为prevent您的VAR的名字从得到精缩。下面是一个例子。

  1. ngmin is a tool that can automate this for you and avoid repetition.
  2. When you're defining factories, controllers, services, etc., you can use array notation with explicit variable naming to prevent your var names from getting minified. An example is below.

BAD


angular.module('MyApp')
    .controller('MyController', function ($scope, OtherDep) {

    });

GOOD


angular.module('MyApp')
    .controller('MyController', ['$scope', 'OtherDep', function ($scope, OtherDep) {

    }]);

注意:当你使用数组表示法,请确保您的'引用'瓦尔都在同一顺序的(注射,瓦尔)

这篇关于JS缩小,Heroku和jQuery.parseJSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆