0

Suppose I have a component

@Component({
  selector: 'mycomponent',
  template: '...'
})
class MyComponent {
}

Normally it renders template under <mycomponnent></mycomponent>, is there a way I could let this component render but by replacing the selector? I saw https://angular.io/docs/ts/latest/api/core/index/ComponentMetadata-class.html but not sure which configuration could lead to such behavior.

Shawn
  • 32,509
  • 17
  • 45
  • 74

1 Answers1

0

This is (at least currently) not supported.

What you can do instead is using an attribute selector like

@Component({
  selector: '[mycomponent]',
  template: '...'
})
class MyComponent {
}

then it can be used with any tag like

<li mycomponent></li> 
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • You mean if I use an attribute selector `
  • ` will be replaced by what's in `template`? I wonder why would selectors have different behaviors when it comes t rendering. – Shawn Jul 18 '16 at 14:10
  • There is nothing being replaced but you (or the user of your component) can freely choose the element name that should become your component. – Günter Zöchbauer Jul 18 '16 at 14:12