Reputation: 6069
I am building a directive in Angular (2+) and I want to limit the directive to which type of element it can be applied to.
Is there a built in Angular mechanism to specify that my directive can only be applied to an <input />
tag? Or will I have to specifically check the element reference?
Upvotes: 4
Views: 1801
Reputation: 28434
As already mentioned in the comments, you can archive this by using a restrictive selector
in the metadata of the directive:
@Directive({
...
selector: 'input[fooDirective]',
exportAs: 'fooDir'
...
})
export class FooDirective {
}
Upvotes: 5