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?

1 Answer 1

2

You need to inject the $compile service into your directive. You can read about dependecy injection in AngularJS here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.