Angular-组件不同的模板 [英] Angular - Component different templates

查看:61
本文介绍了Angular-组件不同的模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个课程"部分.我将此组件用于列表.此列表有时是水平的,有时是垂直的.我可以在组件内部动态选择模板文件吗?

I have a component "course". I use this component to a list. This list sometimes is horizontal and some times is vertical. Can I choose dynamicaly inside the component the template file?

@Component({
    selector: 'course',
    templateUrl: getTemplateFile()
})

类似的功能会很棒!

推荐答案

我认为本教程非常有帮助

I think that this tutorial is very helpful

https://scotch.io/tutorials/component-inheritance-in-角2

您可以简单地扩展基本组件并覆盖模板.这样一来,您可以拥有功能完全相同但模板不同的不同组件.

You can simply extend your base component and overwrite the template. This allows you to have different components with the exact same functionality, but different templates.

这篇关于Angular-组件不同的模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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