如何在Angular中重用模板HTML块? [英] How to reuse template HTML block in Angular?

查看:147
本文介绍了如何在Angular中重用模板HTML块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设文件中有html块:

Lets suppose we have html block in file:

<div id="text">Text</div>

如何在同一文件中重复使用下面的html代码,我的意思是这样的:

How can I reuse this html code below in the same file, I mean something like this:

<re-use id="text"></re-use>

有可能吗?

推荐答案

我认为您想再次重用相同的html块.如果我正确理解您的要求,则以下代码应会有所帮助

I think you wanted to reuse the same html block again. If i understand you correctly, below code should help

<ng-template #MsgRef >
        {{ mycontent }}
</ng-template>

要在同一模板中重复使用以上代码块,

To reuse above block in the same template,

 <ng-template [ngTemplateOutlet]="MsgRef"></ng-template> //reuse any number of times

这篇关于如何在Angular中重用模板HTML块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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