这是我的代码:
<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>
有人知道这个错误有什么可能吗? 在此先感谢:)
答案 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)
将您的最后一个其他人改为