0

I'm getting following error on using fullDate filter inside my html:

Error: [ngModel:nonassign] Expression 'publisherForm.dt | date:'fullDate'' is non-assignable. Element:

Here is my jade code:

datepicker.well.well-sm(ng-model="publisherForm.dt", show-weeks="false", min-date="minDate")

input.form-control(type="text", ng-model=" publisherForm.dt | date:'fullDate' ", readonly='')

what I'm trying is show the selected date from ui-datepicker to user in another input field. Since I want to show only date, I'm using fullDate filter but in console I'm getting above mentioned error.

Any idea what can be the possible reason ?

4
  • 1
    can't use filters in ng-model. it's expression has to resolve to a scope variable. Will need to create directive to parse the $viewModel Commented Aug 24, 2015 at 19:29
  • And how exactly can I do that ? Commented Aug 24, 2015 at 19:31
  • Shouldn't be hard to find numerous solutions in posts here and in google tutorials, posts etc Commented Aug 24, 2015 at 19:32
  • Is there any other simple way of accomplishing this task ? I just need to show a value in the input box based on some $scope variable with a filter ? Is there anyway to achieve this without making it complicated ? Commented Aug 25, 2015 at 4:18

1 Answer 1

0

On searching through existing threads on SO, I found following threads which helped me to solve my problem:

Using angularjs filter in input element How to format a date using ng-model? AngularJS get formatted date in ng-model

Finally made following lines of code change and it started working fine for me:

$scope.$watch('publisherForm.dt', function(newVal){
  $scope.publisherForm.formattedDate = $filter('date')($scope.publisherForm.dt, 'fullDate');
});

If there is anyone who can suggest a better solution is always welcome.

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.