我已经搜索过并且找不到具有相同情况的人,我使用角度路由在模拟db.json服务器上执行CRUD,并且当我执行'更新'功能,它会更改数据库中的值,但始终会将我重定向到只显示“无法发布/ /”的空白页面。即使请求实际上已经通过。我希望在请求完成后返回/ clients页面。我使用browserify来包含角度和角度路径。在此先感谢:)
// Router
var UNRealtyApp = angular.module('UNRealtyApp', ['ngRoute'])
UNRealtyApp.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/clients', {templateUrl: 'app/views/clients.html', controller: 'clientListCtrl'})
.when('/add-client', {templateUrl: 'app/views/client-add.html', controller: 'clientAddCtrl'})
.when('/edit-client/:id', {templateUrl: 'app/views/client-edit.html', controller: 'clientEditCtrl'})
.otherwise({redirectTo: '/404'});
}]);
//Client CRUD
UNRealtyApp.controller('clientListCtrl', function ($scope, $http){
console.log('clientListCtrl activated')
$http.get('http://localhost:3000/clients/').success(function(data) {
$scope.clients = data;
})
})
UNRealtyApp.controller('clientAddCtrl', function ($scope, $http, $location){
console.log('clientAddCtrl activated')
$scope.master = {};
$scope.activePath = null;
$scope.add_new = function(client, AddNewForm) {
console.log('add_new activated')
$http.post('http://localhost:3000/clients/', client).success(function(){
$scope.reset();
$scope.activePath = $location.path('/clients');
});
$scope.reset = function() {
console.log('reset activated')
$scope.client = angular.copy($scope.master);
};
$scope.reset();
}
})
UNRealtyApp.controller('clientEditCtrl', function ($scope, $http, $location, $routeParams){
console.log('clientEditCtrl activated')
var id = $routeParams.id;
// $scope.activePath = null;
$http.get('http://localhost:3000/clients/' + id).success(function(data) {
$scope.clients = [data];
});
$scope.update = function(client){
console.log('update activated')
$http.put('http://localhost:3000/clients/' + id, client).success(function(data) {
$scope.clients = data;
$scope.activePath = $location.path('clients');
});
};
$scope.delete = function(client) {
console.log('delete activated')
var deleteClient = confirm('Are you sure you want to delete?');
if (deleteClient) {
$http.delete('http://localhost:3000/clients/' + client.id);
$scope.activePath = $location.path('clients');
}
}
})