我们目前正在阅读Lynda的Angular培训视频,但是,我们正在讨论第3章,并且已经遇到了问题。 经过几个小时的调试,它结果是角度的版本。
我们将此作为app.js
angular.module('airline', [])
.config(airlineRouter);
function airlineRouter ($routeProvider) {
$routeProvider
.when('/', {templateUrl: 'partials/destinations.html',
controller: function ($scope) {
$scope.setActive('destinations');
}})
.when('/flights', {template: '<h3>Flights</h3>',
controller: function ($scope) {
$scope.setActive('flights');
}})
.when('/reservations', {template: '<h3>Your Reservations</h3>',
controller: function ($scope) {
$scope.setActive('reservations');
}});
}
该演示使用的AngularJS v1.0.7应该可以正常工作,但是, 升级到AngularJS v1.2.14并且它不起作用。页面上没有任何反应。
任何人都可以对此有所了解吗?
答案 0 :(得分:3)
从Angular 1.2开始,ngRoute
模块为split out into a separate file。您需要将其与AngularJS本身一起包含在页面中。
请注意,这意味着您还需要将模块导入您的模块中:
var yourModule = angular.module("yourModule", [
"ngRoute"
]);
有关详细信息,请参阅latest docs。
答案 1 :(得分:1)
从1.0到1.2有一些变化,可能影响这段代码的变化如下所示。
ngRoute已移至自己的模块:http://docs.angularjs.org/guide/migration#ngroute-has-been-moved-into-its-own-module