简体   繁体   中英

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM