简体   繁体   English

生产中无法访问角度控制器

[英]Angular controller not accessible in production

I have a Symfony project, and as the vast majority working on more than one environments: dev and production, using Angular.js. 我有一个Symfony项目,并且绝大多数人都在多个环境中工作:使用Angular.js进行开发和生产。

At the moment, I have got an Angular controller which is accessible in dev environment, but not in production, throwing the message: "Error: [ng:areq] Argument 'xxxx' is not a function, got undefined". 目前,我有一个Angular控制器,可以在开发环境中访问它,但不能在生产环境中访问它,并抛出一条消息:“错误:[ng:areq]参数'xxxx'不是函数,未定义”。 I have seen the latter message in several threads but none of them helped me. 我在多个线程中看到了后一个消息,但是没有一个对我有帮助。

angular.module('MyApp').controller('MyController', function MyController($scope, MyMapper, _, moment, APP_URL, $location) {

$scope.APP_URL = APP_URL;
$scope.momentjs = moment;
$scope.isLoading = 1;
$scope.page = 1;
$scope.totalPagesNum = 1;
$scope.limit = 20;


// fill the table with data
MyMapper.find($location.search()).then(function(data) {

         // ... 
    })();
}).then(function() {
    $scope.isLoading = false;
});

}); });

If you are minimizing your code (as would be typical in production), you will want to annotate your dependencies since they may get renamed by the minimization script. 如果要最小化代码(这在生产中很常见),则将需要注释依赖项,因为它们可能会被最小化脚本重命名。 In order to do this, use the following pattern for your code: 为此,请对您的代码使用以下模式:

angular.module('MyApp').controller('MyController', 
    ['$scope','MyMapper','_','momemt','APP_URL','$location',
        function($scope, MyMapper, _, moment, APP_URL, $location) {
            /* your code for the controller */
        }
    ]
);

Please see https://docs.angularjs.org/guide/di for more information, particularly the "Dependency Annotation" section and the inline array notation subsection. 请参阅https://docs.angularjs.org/guide/di了解更多信息,尤其是“ Dependency Annotation”部分和inline array notation子部分。

I think the issue is pretty much solved. 我认为这个问题已经解决了。

It turns out that the minified version of vendors.js (vendros.min.js), was not properly loaded in the production environment. 事实证明,vendors.js(vendros.min.js)的缩小版未在生产环境中正确加载。 Therefore, I had to point to the correct one in my Gruntfile.js. 因此,我必须在我的Gruntfile.js中指向正确的目录。

Secondly, I refactored my controllers according to AngularJS online guide, as per Brad. 其次,按照Brad的说明,我根据AngularJS在线指南重构了控制器。

Thanks everyone involved. 谢谢大家参与。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM