Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
like image 625
Oussama Gammoudi Avatar asked Jun 12 '15 16:06

Oussama Gammoudi


1 Answers

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

like image 198
unobf Avatar answered Oct 24 '22 00:10

unobf