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

1 に答える 1

14

「すべての注釈スタイルは同等であり、インジェクションがサポートされている Angular のどこでも使用できます。」-- DI ドキュメント

リンク関数はインジェクションをサポートしていないため、インライン アノテーション(またはその他の DI アノテーション スタイル) を使用することはできません。

于 2013-06-05T18:31:16.313 に答える