【问题标题】:Error: $injector:modulerr Module Error in angular错误:$injector:modulerr 角度模块错误
【发布时间】:2016-04-05 13:33:56
【问题描述】:
var myapp = angular.module('myapp', []);

    myapp.config(function($interpolateProvider) {
      $interpolateProvider
        .startSymbol('{[')
        .endSymbol(']}');
    });

    myapp.controller('CanvasControls', function($scope) {
        function1($scope);
        function2($scope);
     });

    This code integrate with rails and working in development fine but in production mode it gives below errors.

未能实例化模块 myapp 由于:

Uncaught Error: $injector:modulerr 

/$injector/modulerr?p0=myapp

【问题讨论】:

    标签: javascript angularjs ruby-on-rails-4 angularjs-scope spree


    【解决方案1】:

    在开发中工作正常,但在生产模式下它给出如下 错误

    猜猜你正在压缩代码。我想你必须像这样添加$scope 希望这会有所帮助

    // Changed here Added String '$scope'
        myapp.controller('CanvasControls',['$scope', function($scope) { 
                function1($scope);
                function2($scope);
             }]);
    

    编辑

    如果您尚未修改 .config 部分,请尝试进行以下更改。

    customInterpolationApp.config(['$interpolateProvider', function($interpolateProvider){
     $interpolateProvider.startSymbol('//');
        $interpolateProvider.endSymbol('//');
    }]);
    

    More关于此类错误

    【讨论】:

    • 您是否也检查了 .config 部分?
    【解决方案2】:

    在控制器中添加了额外的 ] 语法错误

    myapp.controller('CanvasControls', function($scope) {
         function1($scope);
         function2($scope);
    }]);// remove ']' from here
    

    或者使用小拳头方式

    myapp.controller('CanvasControls', ['$scope',function($scope) {
         function1($scope);
         function2($scope);
    }]);
    

    并且您可能在控制器和 html 中的模块名称 myapp 不匹配 ng-app="myapp"

    【讨论】:

    • 检查控制器中的拼写并查看“myapp”(区分大小写)
    • 感谢@shaishab roy mini-fist way 现在为我工作。
    猜你喜欢
    • 1970-01-01
    • 2017-03-09
    • 1970-01-01
    • 1970-01-01
    • 2017-03-28
    • 1970-01-01
    • 2017-01-20
    • 2016-11-16
    相关资源
    最近更新 更多