更改文字并设置默认值 [英] Changing text and setting a default

查看:66
本文介绍了更改文字并设置默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我常见的Angular组件"messageforStudents".

This is my common Angular component "messageforStudents".

messageforStudents.html:

messageforStudents.html:

<span>{{firstText}}</span>
<span>{{secondText}}</span>

messageforStudents.ts:

messageforStudents.ts:

firstText = "Default text 1.";
secondText = "Default text 2.";

我将在上面的文本中随处使用以上组件.

I will be using the above component everywhere with that text.

但是当我使用 schoolRules.html 中的 messageforStudents 组件时,我想更改< span> {{firstText}}</span> < span> {{secondText}}</span> .我该怎么办?

But when I use the messageforStudents component inside schoolRules.html I want to chnage the text of <span>{{firstText}}</span> and <span>{{secondText}}</span>. How can I do this?

推荐答案

您可以使用 @Input 呈角度.

类似这样的东西

@Input firstText = "Default text 1.";
@Input secondText = "Default text 2.";

然后使用组件

<MessageforStudents [firstText]="foo" [secondText]="bar"></MessageforStudents>

如果不传递 firstText secondText ,它将采用您设置的默认值.

If you don't pass firstText or secondText it'll take the default value you have set.

这篇关于更改文字并设置默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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