ng-click in repeat tr, how to make it to go to the desired page?

33 views Asked by At

Here is my repeat table:

<tr ng-repeat="expenses in vm.expense | orderBy:'days'" 
     class="start-text" ng-click="location.path('/expense/{{expenses._id}}')">

I wanted it to go to /expense/1234 but it does nothing when I click

I also have this button:

<a ui-sref="expense/new">
    <button class="start-expense-btn start-button" 
            style="width:120px;">NEW EXPENSE</button>
</a>

And that one works perfectly, goes to /expense/ with the parameter new.

So how do I get ui-sref into that ng-click (if that is what I have to do).

1

There are 1 answers

3
Sajeetharan On BEST ANSWER

Have a function inside the controller,

$scope.changeLocation = function(expense){
   var pathtoNavigate = "/expense/"+ expense.id;
   $location.path(pathtoNavigate);
}

and pass the expense in the ng-click function,

 ng-click="changeLocation(expenses)"