我有一個日期,我希望它有一個過濾器,所以它會有我想要的格式。爲什麼ngModel不可轉讓
HTML:
<input type="text" id="{{ID}}" ng-style="{color: color}" class="tdate ng-pristine ng-untouched ng-valid" ng-model="time.date | DatePlaceHolder">
過濾器:
function DatePlaceHolder($filter) {
return function (value) {
return $filter('date')(value, "dd/MM/yyyy") || "--/--/----";
}
}
它工作正常,但我不斷收到此錯誤:
Error: [ngModel: nonassign] Expression 'time.date | DatePlaceHolder' is non-assignable. Element: <input type="text" id="{{ID}}" ng-style="{color: color}" class="tdate ng-pristine ng-untouched ng-valid" ng-model="time.date | DatePlaceHolder">
不能在ngModel使用過濾器。顯然你不能將模型值賦給表達式'time.date | DatePlaceHolder'。你應該使用解析器和格式器。 – dfsq