【发布时间】:2014-10-06 22:18:11
【问题描述】:
我正在尝试使用 requireJS 加载 angularJS。但是我总是遇到这个错误:
未捕获的错误:[$injector:modulerr] http://errors.angularjs.org/1.2.21/$injector/modulerr?p0=phoneApp&p1=Error%….org%2F1.2.21%2F%24injector%2Fnomod%3Fp0%3DphoneApp%0A%20%20% 20%20at%20Err......7)
我检查了我的代码很多次,所有脚本都正确加载了,但对这个错误一无所知。以下是我的代码:
- index.html:
<body ng-app="phoneApp"> <div class="container" ng-controller="PhoneListCtrl"> <ul> <li ng-repeat="phone in phones">{{phone.name}}</li> </ul> </div> </body> <script src="bower_components/requirejs/require.js" data-main="scripts/main"></script>
- main.js
require.config({ paths : { jquery : '../bower_components/jquery/jquery.min', angular : '../bower_components/angular/angular.min' }, shim : { angular : { exports : 'angular' } } }); require(['jquery', 'angular'],function($, angular){ angular.module('phoneApp', []) .controller('PhoneListCtrl', function($scope){ $scope.phones = [ {'name': 'Nexus S', 'snippet': 'Fast just got faster with Nexus S.'}, {'name': 'Motorola XOOM™ with Wi-Fi', 'snippet': 'The Next, Next Generation tablet.'}, {'name': 'MOTOROLA XOOM™', 'snippet': 'The Next, Next Generation tablet.'} ]; }); });
【问题讨论】:
-
您可以尝试在 html `' 中移动您的
<script>标记吗? -
在
shimfor angular中,您还应该在exports之前指定deps: ['jquery'],