简体   繁体   English

AngularJS fullDate过滤器不起作用

[英]Angularjs fullDate filter not working

I'm getting following error on using fullDate filter inside my html: 我在HTML内使用fullDate过滤器时遇到以下错误:

Error: [ngModel:nonassign] Expression 'publisherForm.dt | 错误:[ngModel:nonassign]表达式'publisherForm.dt | date:'fullDate'' is non-assignable. 日期:'fullDate'是不可分配的。 Element: 元件:

Here is my jade code: 这是我的翡翠代码:

datepicker.well.well-sm(ng-model="publisherForm.dt", show-weeks="false", min-date="minDate") 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='') 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. 我正在尝试的是在另一个输入字段中从ui-datepicker向用户显示所选日期。 Since I want to show only date, I'm using fullDate filter but in console I'm getting above mentioned error. 由于我只想显示日期,因此我使用了fullDate过滤器,但是在控制台中却遇到了上述错误。

Any idea what can be the possible reason ? 知道可能是什么原因吗?

On searching through existing threads on SO, I found following threads which helped me to solve my problem: 在SO上搜索现有线程时,我发现了以下有助于我解决问题的线程:

Using angularjs filter in input element How to format a date using ng-model? 在输入元素中使用angularjs过滤器 如何使用ng-model格式化日期? AngularJS get formatted date in ng-model AngularJS在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 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM