【发布时间】:2020-04-08 03:05:15
【问题描述】:
在 Angular 2+ 中编写代码
点击<ul><li></li></ul>中的按钮打印*
例如。
单击 1 - 输出为 *
单击 2 - 输出为 **
单击 3 - 输出为 ***
【问题讨论】:
标签: html angular typescript ngfor
在 Angular 2+ 中编写代码
点击<ul><li></li></ul>中的按钮打印*
例如。
单击 1 - 输出为 *
单击 2 - 输出为 **
单击 3 - 输出为 ***
【问题讨论】:
标签: html angular typescript ngfor
只需在触发点击事件后附加“*”即可:
HTML
<p>{{ title }}</p>
<button (click)="addStar()">Add star</button>
TS
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
title = '*';
addStar() {
this.title += '*';
}
}
【讨论】: