我正在使用ngRoute
角度。路由工作正常,但page 1
和page 2
未被設置。在我的CSS文件中,我只是簡單地改變背景顏色進行測試。類沒有采取角度的其他頁面上的行動
<!doctype html>
<html>
<head>
<link rel = "stylesheet" href = "main.css">
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular-route.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.js"></script>
<script src = "main.js"></script>
</head>
<body ng-app = "app">
<div class = "page {{pageClass}}" ng-view></div>
</body>
</html>
這裏是我的JS文件:
var app = angular.module("app", ["ngRoute" , "ngAnimate"]);
app.config(function($routeProvider) {
$routeProvider
.when("/" , {
templateUrl: "intro.html",
controller: "intro-controller"
})
.when("/page1" , {
templateUrl: "page1.html",
controller: "page1-controller"
})
.when("/page2" , {
templateUrl: "page2.html",
controller: "page2-controller"
})
});
app.controller("intro-controller" , function($scope) {
$scope.pageClass = "intro";
});
app.controller("page1-controller" , function($scope) {
$scope.pageClass = "page1";
});
app.controller("page2-controller" , function($scope) {
$scope.pageClass = "page2";
});
這是我的CSS文件
.page {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.intro {
background: blue;
}
.page1 {
background: red;
}
.page2 {
background: green;
}
這將是容易調試,如果你可以把一個plunkr這一點。 –