我正在使用 AngularJS 创建一些 CRUD 页面,并在用户列表页面上,一旦用户单击“编辑
”按钮,我就会尝试重定向到编辑页面。但由于某种原因 $routeProvider
无法正常工作。
这是我的 index.html
显示用户列表
<tr ng-repeat="user in usersData">
<td>{{ user.firstname }}</td>
<td>{{ user.lastname }}</td>
<td>{{ user.jobtitle }}</td>
<td>{{ user.userprofile.sex }}</td>
<td>{{ user.userprofile.maritalstatus }}</td>
<td><a ng-click="editUser(user.id)" class="btn btn-small btn-primary">edit</a></td>
<td><a ng-click="deleteUser(user.id)" class="btn btn-small btn-danger">delete</a></td>
</tr>
我的app.js
var app = angular.module('benefitApp', ['ngRoute']);
app.config(function($routeProvider){
$routeProvider
.when("/editUser/:userId", {
templateUrl : "templates/editUser.html"
});
});
app.controller('userController', ['$scope','$http','$location',function($scope, $http, $location) {
$http.get("https://localhost:8443/benefits/v1/users/").then(function (response){
$scope.usersData = response.data;
});
$scope.editUser = function(userId) {
$location.path('/editUser/' + userId);
}
}]);
我的目录结构如下
src/main/resources/static/js/app.js
src/main/resources/static/css/bootstrap.css
src/main/resources/templates/index.html
src/main/resources/templates/editUser.html
我错过了什么?单击“编辑”按钮后,浏览器中的 URL 更改为 https://localhost:8443/home#!/editUser/1
,但它永远不会路由到 editUser.html
最佳答案
尝试添加此指令和 ng-view 指令 $location.path('editUser/' + userId);
关于javascript - $routeProvider 未重定向到 templateUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44991326/