问题描述
我是新手。 我想动态更改页面内容,或者可能要显示其中包含新内容的新组件。 我的网站上有卡。 请参考链接
我想要更改页面的内容,并在卡上单击的每个按钮上显示不同的内容。 我已经创建了一种方法及其正确的方法。
Component.html
<a href="#" class="btn btn-primary" (click)="onFirstClick()">Go somewhere</a>
component.ts
onFirstClick() {
}
我是否需要创建一个新组件来显示新内容。 我该怎么办? 请帮忙
1楼
Gustavo Morais
1
2019-02-21 10:25:12
好吧,这取决于您要动态更改的内容,但是无论如何,Angular确实很擅长。 例如,如果要在第一次单击时切换按钮的文本,可以执行以下操作:
component.ts:
buttonTxt: string = 'Click me';
onFirstClick() {
this.buttonTxt = 'Button Clicked';
}
component.html:
<a href="#" class="btn btn-primary" (click)="onFirstClick()">{{buttonTxt}}</a>
动态更改页面上的内容是使角度更好的方法,并且有很多不同的方式:ngIf *(根据ts上的布尔变量隐藏或显示html组件)等等。
您可以在这里了解更多信息: :