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

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

问题描述

宣布与选择一个组件后'一些-COMP,使用<有的-COMP>< /有的-COMP> 在一个页面中只能使用一次。我想用它多次任何帮助,下面是一个例子code:

  @Component({选择:一些-COMP'})
@View({模板:组件模板'})
类SomeComponent {}
引导(SomeComponent);


解决方案

自举组件确实是在被看作是一个应用程序,如果你想使用相同的组件多次,你会希望把它做成一个指令然后在您的应用程序,指令,它引导你。

看这菜单组件作为一个例子,你会看到<唱段,菜单项> 组件多次使用以及在&LT ;咏叹调菜单方式> 组件

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

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

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

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