我第一次实施Angular。我在Eclipse中使用工厂,控制器和模板(不知道是否有另一种方式)。所以,我正在重定向到我的index.html页面:
<!DOCTYPE html>
<html id="list" data-ng-app="myApp">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../css/stylesheet1.css" />
<title>App</title>
<!-- Include the AngularJS library -->
<script src="../js/angular/angular.js"></script>
<script src="../js/angular/angular-route.js"></script>
<!-- Modules -->
<script src="../js/app.js"></script>
<script src="../js/factories/objectFactory.js"></script>
<script src="../js/factories/usersFactory.js"></script>
<script src="../js/controllers/headerCtrl.js"></script>
<script src="../js/controllers/listCtrl.js"></script>
<script src="../js/controllers/objectHandlerCtrl.js"></script>
</head>
<body>
<div data-ng-controller="headerCtrl as headerVM">
<nav id="links">
<div class="inner"><button onclick="location.href ='#!/createObject'">Create</button></div>
<div class="inner"><button onclick="location.href ='#!/editUser'">Edit user</button></div>
<div class="inner"><button onclick="location.href ='#!/deleteUser'">Delete user</button></div>
<div class="inner"><button onclick="location.href ='../LogOutServlet'">Exit</button></div>
</nav>
</div>
<div data-ng-view></div>
</body>
</html>
在结束时从第三行开始,我有一个div应该根据上部按钮以角度进行动态更改,但是,虽然按下按钮时URL会发生变化,但此区域为空。
为了协调路线,我有app.js:
angular.module('myApp', ['ngRoute'])
.config(function($routeProvider){
$routeProvider
.when("/", {
controller: "listCtrl",
controllerAs: "listVM",
templateUrl: "listObjectTemplate.html",
resolve: {
delay: function($q, $timeout) {
var delay = $q.defer();
$timeout(delay.resolve, 500);
return delay.promise;
}
}
})
.when("/createObject", {
controller: "objectHandlerCtrl",
controllerAs: "objectHandlerVM",
templateUrl: "noteHandlerTemplate.html"
})
.when("/editObject/:ID", {
controller: "objectHandlerCtrl",
controllerAs: "objectHandlerVM",
templateUrl: "objectHandlerTemplate.html"
})
.when("/deleteNote/:ID", {
controller: "objectHandlerCtrl",
controllerAs: "objectHandlerVM",
templateUrl: "objectHandlerTemplate.html"
});
})
我不会添加更多代码,除非您认为有必要保持这一点。
那么,是否需要其他一些配置?现在,角度部分根本不起作用(无论网址如何变化,div似乎都是空的。)
我正在使用AngularJS 1.6.9。
答案 0 :(得分:1)
尝试删除ng-controller data-ng-controller="headerCtrl as headerVM"
,因为您正在配置路由配置