jQuery UI的日期选择器与Angularjs [英] jQuery ui datepicker with Angularjs

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

问题描述

我想使用jQuery UI的日期选择器与AngularJS。

I want to use jQuery UI datepicker with AngularJS.

我有一个样本,但我的code是行不通的。

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

示例:

<一个href=\"http://www.abequar.net/jquery-ui-datepicker-with-angularjs/\">http://www.abequar.net/jquery-ui-datepicker-with-angularjs/

我的code:

<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();

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

它显示了一个错误类型错误:对象的翻译:没有办法日期选择器

推荐答案

我几乎一模一样code,你和我的工作。

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

你有没有包含在页面jQueryUI.js?

Do you have jQueryUI.js included in the page?

这里有一个小提琴

There's a fiddle here

<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();
                }
            });
        }
    };
});

您还需要在NG-应用=应用程序的地方在HTML

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

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

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