Angular-strap datepicker不会更新现有的模型值

时间:2014-02-12 22:52:57

标签: angularjs datepicker breeze angular-strap

我正在使用来自http://mgcrea.github.io/angular-strap/##datepickers的angular-strap datepicker为我的angularjs SPA项目。当使用ngModel双向绑定编辑现有记录时,Angular不会检测日期字段更改,即使我通过更新另一个非日期字段强制保存表单,新日期也不会在后端更新。这是我的html文件中的相关部分:

<input name="DecisionDatePicker" id="ddpID" type="text" class="form-control input-medium" tabindex="14" placeholder="{{vm.format}}"
   data-date-format="MM-dd-yyyy" 
   data-ng-model="vm.formData.dateDecision"
   data-ng-required="vm.decisionDateRequired"
   bs-datepicker />

我的js文件中没有做任何特殊操作。我使用breezejs进行数据处理,它适用于其他领域。 我究竟做错了什么?任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我解决了一个自定义指令,当bs-datepicker调度blur事件时更新模型:

    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- hybride_320x50 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:320px;height:50px"
     data-ad-client="ca-pub-4134311660880303"
     data-ad-slot="1861097476"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>

我知道这只是一个黑客,而不是问题的最终解决方案。但是,如果你被困住并想继续前进,有时黑客可能会有用。

如果要在更新模型之前操作日期格式,还可以在指令中包含$ filter服务。 ;)

相关问题