2013-06-22 43 views
0

我想在AngularJS中使用$ compile。 我讀了如何使用$編譯http://docs.angularjs.org/api/ng.$compile。 寫在我的應用程序,開始看到錯誤

我的代碼之後:

@EnumeratorDirective =() -> 
    restrict: 'A' 
    scope: 
     count: '@uiCount' 

    link: (scope, element) -> 
     scope.size = element.val().length 

     element.bind 'keyup',() -> 
      scope.size = element.val().length 
      ngApply(scope) 


     el = angular.element('<div class="enumerator">{{ size }} of {{ count }}</div>') 
     $compile(el.contents())(scope) 
     element.parent().append(el) 

而且它的輸出:

ReferenceError: $compile is not defined 
at link (http://10.0.1.100:88/assets/js/app.js:697:9) 
at i (http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:44:6) 
at e (http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:39:307) 
at http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:38:372 
at http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:39:257 
at new S.controller (http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:150:223) 
at d (http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:28:174) 
at Object.instantiate (http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:28:304) 
at http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:52:239 
at http://10.0.1.100:88/assets/js/angular/angular.1.0.7.min.js:43:348 <input enumerator="enumerator" ui-count="13" type="text" required="required" class="ng-isolate-scope ng-scope"> 

我缺少什麼?

回答

2

您需要將$compile服務注入您的指令。你可以在AngularJS here上閱讀關於依賴注入的知識。