5

我想为波斯日期选择器创建一个角度指令,我想使用的 javascript lib 是http://jspersiandatepicker.codeplex.com/,我的代码是:

<input type="text" persiandatepicker ng-model="mydate" />{{mydate}}

directive('persiandatepicker', function() {
  return {
      restrict: 'A',
      require: '?ngModel',
      link: function (scope, element, attrs, ngModel) {
          if (!ngModel) return;

          ngModel.$render = function () {
              element.bind("click", function () {
              PersianDatePicker.Show(this, ngModel.$viewValue || '');
          });

      };
   }
};
});

此代码在单击输入时显示日期选择器并在输入中选择日期时显示,但模型未绑定且未更改我如何在此示例中进行绑定?plunker 中的这个链接是我的代码:http ://plnkr.co/edit/AQsvlbdGHCVpjMeCbR3c?p=preview

4

3 回答 3

3

您需要让 Angular 知道该值已更改。看起来日期选择器调用 _textBox.onchange(); 当它完成更新文本框时,您可以挂钩该事件。您需要将代码包装在

 element.bind("onchange", function () {
     scope.$apply(function() {
         //Code to update model goes here.
         //Basically you will need to copy the textbox's contents to the model,
         // you may wish to convert to a date object as well
     }
 }

angularui datepicker源代码只有 120 行长,如果您正在寻找有关创建 datepicker 指令的示例,它可能是一个很好的资源。

于 2013-11-04T05:53:24.653 回答
2

目前有一个很好的可用。这是一个波斯 angularjs 日历: Amin Rahimi 的 angularjs Datepicker

于 2014-08-13T11:12:41.857 回答
2

你也可以使用这个版本的具有波斯日历的 angular-ui 引导程序:波斯角引导程序

于 2015-04-26T13:51:15.953 回答