一个组件可以有多个模板吗? [英] Can one component have multiple templates?
问题描述
基于我想要放置Angular 2组件的位置,有没有办法使用许多模板文件?
Is there a way for Angular 2 component to use many template files base on where i want to place it?
例如,我有一个login
组件,我想将它两次放置在具有两种不同设计的网站上.
For example, I have a login
component and i want to place it two times on my website with two different designs.
有没有一种方法可以将模板传递给组件?
Is there a way that i can pass template to a component?
推荐答案
不确定NG2是否具有支持此功能的内置方法.我只是使用基本组件类来包含所有或大多数逻辑和数据,而没有html模板.然后,在派生的组件类中,只需声明构造函数调用super(...),并定义相应的html模板即可.
Not sure if NG2 has built-in way to support this. I just used a base component class to contain all or most logic and data, without a html template. Then in derived component classes, just need to declare constructor calling super(...), and define respective html template.
如果您的应用程序很复杂,可能您将使用模块实例化类,然后确保在Component属性中声明moduleId:module.id,否则NG2运行时可能会抱怨无法加载html模板.
If your application is complex, likely you will be using module to instantiate classes, then make sure you declare moduleId: module.id in the Component attribute, otherwise the NG2 runtime may complain the html template could not be loaded.
这篇关于一个组件可以有多个模板吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!