2015-04-01 187 views
0

在Typescript中我有一個Kendo UI datepicker角度指令。當我在一頁上放置2條指令並註釋scope["ngModel"] = _utc;行時,它工作正常,但不能解決我的目的。但是當我取消註釋該行並在第二個指令中選擇日期時,它會清除第一個日曆的值。Kendo UI datepicker角度指令

export class DateUtcDirective { 

    public static $inject: string[] = ["AuthService", "propBagFilter"]; 

    public constructor(
     authService: Services.AuthService, 
     propBagFilter: Function 
     ) { 
     return <ng.IDirective>{ 
      restrict: "A", 
      template: 
      "<div>" + 
      "<div class='input-group'>" + 
      "<input kendo-date-picker k-ng-model='ngModel' k-format='format' k-on-change='select()'/>" + 
      "</div>" + 
      "<div class='input-group' ng-show='isTimeAllowed' >" + 
      "<br />" + 
      "<input kendo-time-picker k-ng-model='ngModel' />" + 
      "</div>" + 
      "</div>", 
      replace: true, 
      scope: { 
       ngModel: "=", 
       paramObject: "=" 
      }, 
      link(scope: ng.IScope, element: any, attrs: any) { 
       var propBag = propBagFilter(scope["paramObject"].props); 
       var authPropBag = propBagFilter(authService.currentUser.props); 

       (<any>scope).select = function() { 
        if (!!propBag["IsUtc"]) { 
         console.log(scope); 
         var localDate = new Date(scope["ngModel"]); 
         var _utc = localDate.toUTCString(); 
         scope["ngModel"] = _utc; 
        } 
       } 
       scope["isTimeAllowed"] = propBag["IsTimeAllowed"] || false; 
       scope["isUtc"] = propBag["IsUtc"] || false; 
       scope["format"] = authPropBag["ShortDatePattern"]; 
      } 
     } 
    } 
} 
+0

我覺得我的代碼是不正確的範圍[ 「ngModel」] = _utc;因爲當我取消註釋此行時,我無法選擇日期(即使頁面上只有一個日曆)。 – 2015-04-06 23:58:27

回答

0

嘗試給id來

<input kendo-time-picker k-ng-model='ngModel' /> 

<input kendo-date-picker k-ng-model='ngModel' k-format='format' k-on-change='select()' id="abc1"/> 
<input kendo-time-picker k-ng-model='ngModel' id="abc2" />