nutzt
nutzt

Reputation: 2923

Angularjs ng-model with filter let me not change

This is my simple form:

 <span>{{ entry.Date | amDateFormat: 'DD.MM.YYYY' }}</span>

By click on a "edit" button, i hide the `span´ and show the form:

<input type="text" ng-model="entry.Date | amDateFormat: 'DD.MM.YYYY'" name="entry" class="input" autocomplete="off">

So, but if i want to change the entry.Date in the form, they delete my new input directly and return to his old state. If i delete the amDateFormat filter, it works :/

Upvotes: 0

Views: 463

Answers (2)

Kalhan.Toress
Kalhan.Toress

Reputation: 21901

use the $filter service inside the controller as below,

Ex:

app.controller("testCtrl" , function($scope, $filter) {
    $scope.entry = {};
    $scope.entry.Date = $filter("amDateFormat")('DD.MM.YYYY');
})

here is the demo Plunker

Upvotes: 0

basarat
basarat

Reputation: 275819

You cannot use a filter in ng-model or any property that any directive would want to assign to.

Upvotes: 1

Related Questions