0

In Angular (2+), typically components would be added to templates using HTML tags, and directives would be added using HTML attributes: in both cases this is achieved through the selector argument within the @Component/@Directive decorator:

<!-- component set up using-- selector: 'my-component' -->
<my-component></my-component>
<!-- directive set up using-- selector: '[myDirective]' -->
<div myDirective></div>

I tested to see if I could set up a directive that will use an HTML tag instead of attribute, and it seemed to work fine:

<!-- directive set up using-- selector: 'my-tag-directive' -->
<my-tag-directive></my-tag-directive>

I would just like to know if this is officially supported in Angular.

7
  • Note: we're currently using Angular 2 so I tested on that, although the intention is to upgrade. Commented Jun 21, 2018 at 15:38
  • By saying "seemed to work fine" you meant that you didn't get any errors or some logic in that Directive works fine? Commented Jun 21, 2018 at 15:39
  • ya angular 5 it is deprecated Commented Jun 21, 2018 at 15:39
  • @Buczkowski I set it up, added it to my template, and added alert('hello') to the ngOnInit, and that worked without generating any errors. Commented Jun 21, 2018 at 15:46
  • @ChellappanV do you have a link? The link provided in stackoverflow.com/a/50972583/2661556 seems to suggest it's allowed. Commented Jun 21, 2018 at 15:47

1 Answer 1

3

Yes it could be tag as well see this documentation for more info

https://angular.io/api/core/Directive#selector

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

2 Comments

But can it be a 'made-up' tag? From the link you have provided (and others I've found) it doesn't look like it. They are just binding to existing, well-established tags, not 'new' ones. I feel you can do this for a component tag, for instance, but not completely generate a new one.
EDIT to previous: Nevermind, I've actually tested this and can confirm THIS WORKS.

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.