【发布时间】:2016-10-11 13:27:33
【问题描述】:
我正在学习 Angular,但我遇到了路由问题。我试图自己解决它,但不知道它会是什么。 这是我的脚本和我的脚本的 Plunker link
var singleApp = angular.module('singleApp', ['ngRoute'])
.config([$routeProvider, $locationProvider, function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'pages/home.html',
controller: 'mainController'
})
.when('/about', {
templateUrl: 'pages/about.html',
controller: 'aboutController'
})
.when('/contact', {
templateUrl: 'pages/contact.html',
controller: 'contactController'
});
// Deletes # in URL with HTML History API
$locationProvider.html5Mode(true);
}])
.controller('mainController', function($scope) {
$scope.message = 'This is the main page';
})
.controller('aboutController', function($scope) {
$scope.message = 'This is the about page';
})
.controller('contactController', function($scope) {
$scope.message = 'This is the message page';
});
我已经在 html 中导入了 Angular 和路由脚本。 这些页面只有 $message
【问题讨论】:
-
在 JS 控制台中:
ReferenceError: $routeProvider is not defined
标签: javascript angularjs