Remove/replace a component’s selector tag from HTML [duplicate]

Replace was deprecated in AngularJS 1.x according to https://github.com/angular/angular/issues/3866 because it seemed to not be a good idea.

As a workaround you can use an attribute selector in your component like

selector: '[my-component]'

selector: '[myComponent]'

and then use it like

<div my-component>Hello My component</div>

<div myComponent>Hello My component</div>

hint

Directive selectors should be camelCase instead of snake-case.
Snake-case is only used for element selectors, because the - is required for custom elements. Angular doesn’t depend on components being custom elements, but it’s considered good practice to comply with this rule anyway.
Angular works fine with camelCase attributes and uses them with all directives (*ngFor, ngModel, …), and is also suggested by the Angular style guide.

Leave a Comment