3

I'm writing a wrapper for a jQuery element that is part of a template I'm working with.

The link method in the example here: http://jsfiddle.net/Webnet/ugSsk/ is not triggered. I can't get it to output to the console or alert.

Any suggestions?

JS:

angular.module('test', []).
    directive('slideToggle', function () {
        return {
            scope: false,
            replace: true,
            template: '<input type="checkbox" name="" class="slideToggle"/>',
            link: ['scope', 'element', 'attrs', function (scope, element, attrs) {
                console.log(element);
                alert('linked');
            }],
            controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {

            }]
        }
    });

HTML:

<div ng-app="test">
    <div slide-toggle on="Active" off="Inactive"></div>
</div>
2
  • There is no need for injecting arguments into your linking function like that. That's why it's not working. Commented Jun 5, 2013 at 18:27
  • you are using wrong syntax you should not be using minification syntax with link function Commented Jun 5, 2013 at 18:29

1 Answer 1

14

"all of the annotation styles are equivalent and can be used anywhere in Angular where injection is supported." -- DI doc

Since the link function doesn't support injection, you can't use the inline annotation (or any other DI annotation style) there.

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

1 Comment

There seem to be a lot of questions/answers for the link function not working. Many of the other ones didn't do anything for me, but this one fixed it.

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.