I have to send the ID of a client to the modify.html page from the clients.html page when I clic on the Modify link,this is what I have done:
clients.html:
<tbody>
<tr ng-repeat="post in posts>
<td align="center">{{post.id}}</td>
<td align="center">{{post.nom}}</td>
<td align="center"><a ui-sref="app.modifier({customerID:post.id})">Modify</a></td>
</tr>
</tbody>
Modify.html:
<div class="form-group">
<label class="col-sm-1 control-label">Nom:</label>
<div class="col-sm-1">
<input type="text" class="form-control rounded" ng-model="usernom">
</div></div>
and the controller:
.controller('editController', ['$scope', '$http' ,function($scope,$http) {
$scope.errors = [];
$scope.msgs = [];
$scope.usershow = function() {
$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);
$http({method: 'GET', url: 'MyURL?id='+$scope.userid+'&nom=test}).success(function(data, status, headers, config){
if (data.msg != '')
{
$scope.msgs.push(data.msg);
}
else
{
$scope.errors.push(data.error);
}
}).error(function(data, status) {
$scope.errors.push(status);
});}}])
and the config.router.js:
.state('app.modifier', {
url: 'client/modifier/:customerID',
templateUrl: 'tpl/modify.html',
controller: 'editController'
})
I can get the ID selected from the table in the URL of tha browser but I can't send it to the HTTP request
thanks for help
update:
this my essai:
$http({method: 'GET', url: 'MyURL?id='+$stateParams.customerID +'&nom=test}).success(function(data, status, headers, config){ ....
but I get this error:
ReferenceError: $stateParams is not defined
Just inject $stateParams in controller handling your Modify.html and set $stateParams.customerID to your $http request.