2013-08-28 54 views
0

我想寫一個指令jquery easy pie chartsjQuery的插件easyPieChart指令angularJS

繼教程,這是到目前爲止我的代碼..

angular.module('ysf.easyPieChart', []).directive('easyPieChart', function() { 
    return { 
     restrict: 'C', 
     scope: { 
      percent: '=' 
     }, 
     link: function(scope, elem, attrs) { 
      support._debug(elem.easyPieChart, 'element value'); 
      support._debug(scope.percent, 'scope value'); 
      //support._debug(this, 'this'); 
      $(elem.easyPieChart).easyPieChart(); 
     } 
    } 

}); 

這該是多麼我從我的模板調用它

<div class='easyPieChart' percent='73'>73</div> 

1.it並畫了一個圈,但它不是它應該在的地方。 2.它不填滿我適量的百分比。

鉻控制檯給我這個錯誤。

TypeError: Cannot call method 'createDocumentFragment' of null 

thnakyou。

+0

你能創建一個jsfiddle嗎? – zsong

+0

其實我解決了問題 – debuggerpk

+0

很酷。然後寫一個答案並將其標記爲已解決。 – zsong

回答

0

這是代碼應如何,該要素是使用ELEM [0]

angular.module('ysf.easyPieChart', []).directive('easyPieChart', function() { 
    return { 
     restrict: 'C', 
     scope: { 
      percent: '=' 
     }, 
     link: function(scope, elem, attrs) { 
      support._debug(elem.easyPieChart, 'element value'); 
      support._debug(scope.percent, 'scope value'); 
      //support._debug(this, 'this'); 
      $(elem[0]).easyPieChart(); 
     } 
    } 

});