Grunt构建到nginx会导致错误(angularJS)

时间:2014-05-07 10:14:10

标签: angularjs nginx gruntjs yeoman-generator-angular

我有一个简单的AngularJS应用程序,我使用grunt serve来构建代码并对其进行测试。我现在希望使用nginx将代码部署到服务器,并且我使用grunt build任务生成代码,该任务在./dist文件夹中生成代码。我现在希望将此代码转移到可以托管它的服务器上。

我不知道错误是否与缩小代码有关,但应用程序无法运行。

错误是:

    Error: [$injector:unpr] Unknown provider: aProvider <- a
http://errors.angularjs.org/1.2.6/$injector/unpr?p0=aProvider%20%3C-%20a
    at http://localhost/kds/scripts/ded94bd9.vendor.js:3:30474
    at http://localhost/kds/scripts/ded94bd9.vendor.js:4:13890
    at Object.c [as get] (http://localhost/kds/scripts/ded94bd9.vendor.js:4:13194)
    at http://localhost/kds/scripts/ded94bd9.vendor.js:4:13985
    at c (http://localhost/kds/scripts/ded94bd9.vendor.js:4:13194)
    at d (http://localhost/kds/scripts/ded94bd9.vendor.js:4:13440)
    at Object.e [as instantiate] (http://localhost/kds/scripts/ded94bd9.vendor.js:4:13587)
    at http://localhost/kds/scripts/ded94bd9.vendor.js:4:29734
    at http://localhost/kds/scripts/ded94bd9.vendor.js:4:22719
    at f (http://localhost/kds/scripts/ded94bd9.vendor.js:3:30909) 

这里出了什么问题?

编辑此外,在Chrome网络日志中:http://cl.ly/image/3z0v3X2n1f3h

nginx.conf的conf部分:

    location /kds/ {
            alias /Users/asheshambasta/code/kds/dist/;
            index  index.html index.htm;
    }

grunt serve可以毫无问题地加载应用程序。

1 个答案:

答案 0 :(得分:0)

当您在AngularJS中看到错误时,例如&#34;未知提供商:aProvider&lt; - a&#34;或者&#34;未知提供者:nProvider&lt; - n&#34;,这意味着AngularJS依赖注入系统无法将参数与提供者匹配。当你在一个不存在的注入函数中有一个参数时,这个错误是合法的,但是......

更常见的是,你的AngularJS代码被缩小了,这需要一些工作。您必须以某种方式注释您的控制器/服务/等,以便AngularJS的依赖注入系统找到它。有关详细信息,请参阅the docs(搜索&#34;缩小和#34;),但这是一个快速的简要说明:

// This injects $scope and $http as the two arguments to the controller.
myApp.controller("MyCtrl", ["$scope", "$http", function($scope, $http) { ... }]);

另一个选项是在构建配置中禁用缩小。

相关问题