2014-12-07 41 views
1

我有以下包含在AngularJS指令中的kendoDatePicker;該指令應該顯示選擇器打開日曆,但不是。這段代碼有什麼問題? This is the plunk如何在AngularJS指令鏈接中聲明Kendo UI對象

HTML:

<dir2></dir2> 

的Javascript:

var app = angular.module("app", [ "kendo.directives" ]); 

    function MyCtrl($scope) { 

} 



app.directive('dir2', function() { 

    var directive = {}; 

    directive.restrict = 'A'; 

    directive.template = '<input kendo-date-picker="picker" />'; 

    directive.link = function (scope, element, attrs) { 

     scope.picker.open(); 

    }; 

    return directive; 
}); 

回答

0

這是解決方案:

在那裏說

scope.picker.open(); 

應該說

$timeout(function() { 
      scope.picker.open(); 
    }, 1); 
+0

你不需要100毫秒。您只需將其推送到在之前的模板中呈現的下一個摘要循環中。 – PSL 2014-12-27 17:16:52

+0

更改爲1毫秒 – ps0604 2014-12-31 14:53:30

0

你應該定義directive.restrict =,而不是 'A' 'E'。

'A'表示屬性,'E'表示元素。

app.directive('dir2', function() { 

    var directive = {}; 

    directive.restrict = 'E'; 

    directive.template = '<input kendo-date-picker="picker" />'; 

    directive.link = function (scope, element, attrs) { 

     scope.picker.open(); 

    }; 

    return directive; 
}); 
+0

抱歉...固定它,但它仍然沒有工作,我得到'無法讀取未定義的屬性'open'[見plunk](http://plnkr.co/edit/RfHQqDv8boJJrFSpbW5H?p=preview) – ps0604 2014-12-07 13:17:34

+0

什麼是試圖打開的scope.picker.open()? – user3063182 2014-12-07 13:23:24

+0

這只是一個例子。 scope.picker.open()應該打開日期選擇的日曆。我的問題是,scope.picker是未定義的,我無法獲得指令中的對象句柄。 – ps0604 2014-12-07 13:27:39

相關問題