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>
Ben
  • 60,438
  • 111
  • 314
  • 488

1 Answers1

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.

Mark Rajcok
  • 362,217
  • 114
  • 495
  • 492
  • 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. – Jason Swett Nov 18 '15 at 21:46