balteo
balteo

Reputation: 24679

Using the "require:" attribute in order to require several Angular directives

Is it possible to use the require attribute in order to require several directives instead of just one?

If so can I pass an array of directives to this require attribute?

Upvotes: 1

Views: 42

Answers (2)

rajasaur
rajasaur

Reputation: 5460

Yes, its possible to pass an array or a string. From the source:

Require another directive and inject its controller as the fourth argument to the linking function. Therequiretakes a string name (or array of strings) of the directive(s) to pass in.

Upvotes: 2

Nikos Paraskevopoulos
Nikos Paraskevopoulos

Reputation: 40298

Yes, it is possible:

.directive("...", function() {
    return {
        ...
        require: ["ngModel", "foo", "bar"],
        link: function(scope,elem,attrs.ctrl) {
            var
                ngModelCtrl = ctrl[0],
                fooCtrl     = ctrl[1],
                barCtrl     = ctrl[2];
            ...
        }
    };
});

Upvotes: 3

Related Questions