简体   繁体   English

如何使用Angularjs调用datepicker

[英]How to call the datepicker using Angularjs

I want to call datepicker using angularjs. 我想使用angularjs调用datepicker。 I have tried with some piece of code, can someone help me on what is missing. 我尝试了一些代码,有人可以帮助我解决所缺少的内容。 In html tag getting "unknown attribute datepicker". 在html标记中获取“未知属性datepicker”。 Appreciate you help.Thanks. 感谢您的帮助。

<input ng-model="datePicker" id="txt_parentcrid" type="text" placeholder=":input" datepicker/>
   var app = angular.module("myApp", []);
    app.directive("datepicker", function () {
        return {
            restrict: "A",
            require: "ngModel",
            link: function (scope, elem, attrs, ngModelCtrl) {
                var updateModel = function (dateText) {
                    scope.$apply(function () {
                        ngModelCtrl.$setViewValue(dateText);
                    });
                };
                var options = {
                    dateFormat: "dd/mm/yy",
                    onSelect: function (dateText) {
                        updateModel(dateText);
                    }
                };
                elem.datepicker(options);
            }
        }
    });

Like Pankaj mentioned in the comments, sounds like you are missing some file. 就像评论中提到的Pankaj一样,听起来好像您缺少一些文件。 Make sure you are including everything in the right order. 确保以正确的顺序包含所有内容。 Simple things like adding jQuery before jQuery UI might be your answer. 像在jQuery UI之前添加jQuery这样的简单事情可能就是您的答案。

Working example 工作实例

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

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