1

this is my filter function(from json date convert):

app.filter("mydate", function () {
var re = /\/Date\(([0-9]*)\)\//;
return function (x) {
    var m = x.match(re);
    if (m) return new Date(parseInt(m[1]));
    else return null;
};

});

no problem if I use it here:

{{k.StartDate | mydate | date: 'yyyy-MM-dd HH:mm'}}

I want to use this filter in input , but I'm getting this error:

error

I use the filter like this

<input class="w-100" datetime="yyyy-MM-dd" ng-model="ApplyToProgress.CurrentWork.StartDate | mydate | date: 'yyyy-MM-dd HH:mm'" type="text">

1 Answers1

0

You can't use a filter on ng-model. I suggest you watching the changes with ng-change and applying the filter on the controller, like this:

<input class="w-100" datetime="yyyy-MM-dd" ng-model="ApplyToProgress.CurrentWork.StartDate" ng-change="applyFilter()" type="text">

And in the controller:

$scope.applyFilter = function(){
    $scope.ApplyToProgress.CurrentWork.StartDate = $filter('mydate')($scope.ApplyToProgress.CurrentWork.StartDate);
    $scope.ApplyToProgress.CurrentWork.StartDate = $filter('date')($scope.ApplyToProgress.CurrentWork.StartDate, 'yyyy-MM-dd HH:mm');
    }
Gobli
  • 327
  • 2
  • 12