Search code examples
angularjsangularjs-ng-clickui-sref

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


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).


Solution

  • 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)"