即使一切正常,我也会得到Uncaught Error:[$ injector:modulerr]

时间:2014-09-15 11:52:01

标签: angularjs

这是我的代码:

<body ng-app="MyApp">
    <div ng-view></div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular-route.min.js"></script>
    <script >
        var app = angular.module('MyApp', ['ngRoute']); 
        app.config(function($routeProvider) {
            $routeProvider
                .when('/', {templateUrl: 'partials/products.html', controller : 'ProductsCtrl'})
                .when('/product/:id', {templateUrl: 'partials/product.html', controller : 'ProductCtrl'})
                .otherwhise({redirectTo: '/'});
        });
        app.controller('ProductsCtrl', function($scope) {
            $scope.products = [];
        });

        app.controller('ProductCtrl', function($scope) {
            $scope.product = [];
        });
    </script>
</body>
</html>

有人知道这个错误有什么可能吗? 在此先感谢:)

2 个答案:

答案 0 :(得分:0)

<script>放在app语句

之前
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.24/angular-route.min.js"></script>
</head>
<body ng-app="MyApp">
<div ng-view></div>

<script >
    var app = angular.module('MyApp', ['ngRoute']); 
    app.config(function($routeProvider) {
        $routeProvider
            .when('/', {templateUrl: 'partials/products.html', controller : 'ProductsCtrl'})
            .when('/product/:id', {templateUrl: 'partials/product.html', controller : 'ProductCtrl'})
            .otherwhise({redirectTo: '/'});
    });
    app.controller('ProductsCtrl', function($scope) {
        $scope.products = [];
    });

    app.controller('ProductCtrl', function($scope) {
        $scope.product = [];
    });
</script>

答案 1 :(得分:0)

将您的最后一个其他人改为