我在从表格中将ID发送到页面clientMdodify.html时遇到问题,这就是我所做的:
Clients.html,我在其中调用clientModify.html:
<table class="table table-striped table-bordered" style="text-align:center" id="table" >
<thead>
<th align="center">Référence</th><th align="center">Nom</th><th>Prenom</th><th>Email</th><th>Adresse Facturation</th><th colspan="2">Actions</th>
</thead>
<tbody>
<tr ng-repeat="post in posts" >
<td align="center">{{post.id}}</td>
<td align="center">{{post.nom}}</td>
<td align="center">{{post.email}}</td>
<td align="center">{{post.adresse}}</td>
<td align="center"><a ui-sref="app.modify">Modify</a></td>
</tr>
</tbody>
</table>
这是路由的config-router.js:
.state('app.modify', {
url: 'client/modify/:customerID',
templateUrl: 'tpl/clientMdodify.html,
controller: 'editCtrl',
resolve: {
customer: function(services, $route){
var customerID = $route.current.params.customerID;
return services.getCustomer(customerID);
}
}
})
app.js:
angular.module('app', [
'ngAnimate',
'ui.router',
'ngRoute',
'pascalprecht.translate'
]).factory("services", ['$http', function($http) {
var serviceBase = 'services/'
var obj = {};
obj.getCustomers = function(){
return $http.get(serviceBase + 'clients');
}
obj.getCustomer = function(customerID){
return $http.get(serviceBase + 'client?id=' + customerID);
}
obj.insertCustomer = function (customer) {
return $http.post(serviceBase + 'insertClient', customer).then(function (results) {
return results;
});};
obj.updateCustomer = function (id,customer) {
return $http.post(serviceBase + 'updateClient', {id:id, customer:customer}).then(function (status) {
return status.data;
});
};
obj.deleteCustomer = function (id) {
return $http.delete(serviceBase + 'deleteClient?id=' + id).then(function (status) {
return status.data;
});
};
return obj;
}]).controller('editCtrl', function ($scope, $rootScope, $location, $routeParams, services, customer) {
$scope.errors = [];
$scope.msgs = [];
var customerID = ($routeParams.customerID) ? parseInt($routeParams.customerID) : 0;
$rootScope.title = (customerID > 0) ? 'Edit Customer' : 'Add Customer';
$scope.buttonText = (customerID > 0) ? 'Update Customer' : 'Add New Customer';
var original = customer.data;
original._id = customerID;
$scope.customer = angular.copy(original);
$scope.customer._id = customerID;
$scope.isClean = function() {
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
return angular.equals(original, $scope.customer);
}
$scope.deleteCustomer = function(customer) {
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
$location.path('/');
if(confirm("Est ce que vous voulez supprimer ce client: "+$scope.customer._id)==true)
services.deleteCustomer(customer.id);
};
$scope.saveCustomer = function(customer) {
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
$location.path('/');
if (customerID <= 0) {
services.insertCustomer(customer);
}
else {
services.updateCustomer(customerID, customer);
}};})
感谢您的帮助
答案 0 :(得分:0)
可以使用 ui-sref 属性发送参数,如下所示:
<td align="center"><a ui-sref="app.modify({customerID: <your_customer_id>})">Modify</a></td>