带有 Angularjs 的 jQuery ui 日期选择器 [英] jQuery ui datepicker with Angularjs

查看:33
本文介绍了带有 Angularjs 的 jQuery ui 日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 AngularJS 中使用 jQuery UI 日期选择器.

I want to use jQuery UI datepicker with AngularJS.

我有一个示例,但我的代码不起作用.

I have a sample , but my code is not working.

示例:

http://www.abequar.net/jquery-ui-datepicker-with-angularjs/

我的代码:

<input id="sDate" name="programStartDate" type="text" datepicker required/>



angular.module('elnApp')
 .directive('datepicker', function () {
  return {
    restrict: 'A',
    require : 'ngModel',
    link : function (scope, element, attrs, ngModelCtrl) {
        $(function(){
            element.datepicker({
                dateFormat:'yy-mm-dd',
                onSelect:function (date) {
                    ngModelCtrl.$setViewValue(date);
                    scope.$apply();

                }
            });
        });
    }
} });

显示错误TypeError: Object [object Object] has no method 'datepicker'.

推荐答案

我的代码与你和我的作品几乎完全相同.

I have almost exactly the same code as you and mine works.

页面中是否包含 jQueryUI.js?

Do you have jQueryUI.js included in the page?

有一个小提琴这里

<input type="text" ng-model="date" jqdatepicker />
<br/>
{{ date }}


var datePicker = angular.module('app', []);

datePicker.directive('jqdatepicker', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
         link: function (scope, element, attrs, ngModelCtrl) {
            element.datepicker({
                dateFormat: 'DD, d  MM, yy',
                onSelect: function (date) {
                    scope.date = date;
                    scope.$apply();
                }
            });
        }
    };
});

您还需要在 HTML 中的某处使用 ng-app="app"

You'll also need the ng-app="app" somewhere in your HTML

这篇关于带有 Angularjs 的 jQuery ui 日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆