How to use an AngularJS 2 component multiple times in the same page?

6k views Asked by At

After declaring a component with selector 'some-comp', using <some-comp></some-comp> in a page will only work once. I would like to use it multiple times any help, here is an example code:

@Component({ selector: 'some-comp' })
@View({ template: 'component template' })
class SomeComponent {    }
bootstrap(SomeComponent);
1

There are 1 answers

1
unobf On BEST ANSWER

The bootstrapped Component is really to be looked at as an app, if you want to use the same component multiple times, you will want to make it into a directive and then include that directive in your app which you bootstrap.

Look at this menu component as an example, you will see the <aria-menuitem> components used multiple times as well as the <aria-menu> components.

https://github.com/dylanb/Axponents/tree/master/angular2