【发布时间】:2018-04-26 14:58:14
【问题描述】:
这是我的过滤功能(来自 json 日期转换):
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;
};
});
如果我在这里使用它没问题:
{{k.StartDate | mydate | date: 'yyyy-MM-dd HH:mm'}}
我想在 input 中使用这个过滤器,但是我收到了这个错误:
我使用这样的过滤器
<input class="w-100" datetime="yyyy-MM-dd" ng-model="ApplyToProgress.CurrentWork.StartDate | mydate | date: 'yyyy-MM-dd HH:mm'" type="text">
【问题讨论】:
-
是的。您无法过滤模型。
-
you can't filter an ng-model。我认为您想要的解决方案是自定义指令而不是过滤器。在指令中应用更改,可能使用
ngModel.$parsers.push(function (input) { ... -
尝试使用
标签: c# .net angularjs json datetime