如何在同一页面中多次使用AngularJS 2组件? [英] How to use an AngularJS 2 component multiple times in the same page?

查看:287
本文介绍了如何在同一页面中多次使用AngularJS 2组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用选择器'some-comp'声明组件之后,在页面中使用<some-comp></some-comp>将只工作一次.我想多次使用它,这是示例代码:

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.

以这个菜单组件为例,您将看到<aria-menuitem>组件被多次使用以及<aria-menu>组件.

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

这篇关于如何在同一页面中多次使用AngularJS 2组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆