【发布时间】:2015-02-06 18:54:03
【问题描述】:
我正在尝试将 angularJS 与来自该站点的 datepicker 相关联:http://freqdec.github.io/datePicker/ 根据文档,这就是它基于Id创建日期选择器的方式,它只能由Id完成,而不是类,而不是jquery obj。
datePickerController.createDatePicker({
formElements:{
"inp1":"%d/%m/%Y"
}
});
我正在创建一个指令来做到这一点:
.directive('datepicker', function() {
return {
restrict : 'A', // the directive is restricted to an attribute
require : 'ngModel',
link : function(scope, element, attrs, ngModelCtrl) { // the link() function is used to setup the datepicker
// http://freqdec.github.io/datePicker/
var id = attrs.id;
var dateFormat = "%m/%d/%Y";
var fe = {}
fe[id + ''] = dateFormat;
datePickerController.createDatePicker({
// Associate the text input to a MM/DD/YYYY date format
formElements : fe
});
}
}
})
当我调试时,在调用之前
datePickerController.createDatePicker({
// Associate the text input to a MM/DD/YYYY date format
formElements : fe
});
我明白了
$(id)
返回空。
[]
然后我意识到没有创建 html 元素,因为我看到了
element
有点像
<input class="col-xs-10 noPadding datepicker ng-pristine ng-untouched ng-valid" datepicker="" id="{{'licEffDate'+$index}}" ng-model="license.licEffDate">
元素中的id还没有被评估。
但我只能准备好这个 id 以便将它传递给日期选择器。
有没有办法解决这个问题?
【问题讨论】:
-
与论坛网站不同,我们不使用“谢谢”、“感谢任何帮助”或Stack Overflow 上的签名。请参阅“Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?。顺便说一句,这是“提前致谢”,而不是“致谢”。
标签: jquery angularjs datepicker