1

I'm building up an app using ng-routes. What i'm doing is get info from an api on a list, and i need send a value into the url, because the next page -the detail page of that id- will catch the value.

Next, part of my code. First, i'm getting the info

function getData(){
    $http.get('/api/info')
    .then(function(response){
        $scope.fill = response.data;
        //console.log($scope.fill);
    });
}

And on my html view:

<tbody>
<tr ng-repeat="a in fill">
    <th>{{a.Id}}</th>
    <th>{{a.Name}}</th>
    <th>{{a.ContactStatus}}</th>
    <th>{{a.UserAsigned}}</th>
    <th><a ng-click="obtainId(a)">See more</a></th>
</tr>
</tbody>

Then, this is the part of the code where i get the id on click

$scope.obtainId = function(a){
    $scope.sendId = a.Id;
    console.log($scope.sendId);
}

My problem comes when i want to send the id to the detail page. I've found the next code to send to another page with ng-routes:

$scope.goToDetail = function(hash){
        $location.path(hash);
    }

And on the html views:

<button class="btn btn-danger" ng-click="goHome('/detail')"></button>

I've tested first this last code, and it works; it open the detail page. Now, how can i send the obtained id (with the onclick action) on the url to the detail page using the $location.path code?

I'm using Javascript and AngularJs.

Hope you can help me.

georgeawg
  • 48,608
  • 13
  • 72
  • 95

0 Answers0