Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ngModel non-assignable

I have a date and i want it to have a filter on it so it would have the format i want for it.

html:

<input type="text" id="{{ID}}" ng-style="{color: color}" class="tdate ng-pristine ng-untouched ng-valid" ng-model="time.date | DatePlaceHolder">

filter:

function DatePlaceHolder($filter) {
    return function (value) {
        return $filter('date')(value, "dd/MM/yyyy") || "--/--/----";
    }
}

It works fine but I keep getting this error:

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">
like image 952
Meinhh Avatar asked Dec 14 '22 11:12

Meinhh


1 Answers

ng-model is to bind model with views to take input or display view. you cant use filter on ng-model.

If you want to display data only, then you can use ng-bind for non input elements, and ng-value for form elements.

Here is example.

$scope.someValue='Value in controller'

like image 94
Laxmikant Dange Avatar answered Dec 17 '22 02:12

Laxmikant Dange