0

I'm trying to use the $compile in AngularJS. I'm Read how to use $compile in http://docs.angularjs.org/api/ng.$compile. Wrote it in my app, after starting the see the error

My code:

@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)

And it's output:

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"> 

What am I missing?

4

1 回答 1

2

您需要将$compile服务注入到您的指令中。您可以在此处阅读有关 AngularJS 中的依赖注入的信息。

于 2013-06-22T11:32:25.400 回答