user3323438 user3323438 - 4 months ago 7
AngularJS Question

how to send filtered paramter to a function in angular js?

I want to send filtered date as parameter to my function, fetchData(), i tried something like this, but its giving errors. what is the correct way of doing it?

<button type="button" ng-click="gridDataCtrl.fetchData(selectedUser.name,myDate | date:'dd-MM-yyyy')">Refresh</button>

Answer

You can do filter in controller

HTML:

<button type="button" ng-click="gridDataCtrl.fetchData(selectedUser.name,myDate)">Refresh</button>

In controller(make sure that you inject $filter):

vm.fetchData = function(name, date){
  date = $filter('date')(date, 'dd-MM-yyyy');
}