指令、ngModelController 和 viewValue 更新

Directives, ngModelController and viewValue update

我目前正在重构我们的旧指令,它基本上以本地日期格式显示日期,同时将 ISO 日期保留为基础模型。我依赖 ngModel 控制器、解析器、格式化程序等。除了一件事外,它基本上按预期工作。

一个日期选择器可以有一个 startBoundary 参数。设置时,如果 startBoundary 日期是将来的日期,则指令的当前值应设置为此 startBoundary,当然,输入字段中显示的值也会更新。但到目前为止,即使我的 modelValue 已正确更新,字段中显示的值仍未正确更新。我虽然遇到了摘要问题,但到目前为止还没有成功。

这是一个代码笔,演示了会发生什么:http://codepen.io/pabuisson/pen/dPRNbb

知道如何解决这个问题吗?我不明白。非常感谢你们!

您只需拨打电话$render:

modelCtrl.$setViewValue moment.utc(start).format( dateFormat )
modelCtrl.$render()

演示: http://codepen.io/anon/pen/xbrPbB