如何编写角度为2+的*(star)程序

问题描述 投票:-2回答:1

在Angular 2+中编写代码

单击<ul><li></li></ul>中的按钮打印*

例如。

点击1-输出为*

点击2-输出为**

点击3-输出为***

html angular typescript ngfor
1个回答
0
投票

仅在触发点击事件后添加'*':

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 += '*';
  }
}

供您参考:https://stackblitz.com/edit/angular-tdw4es

© www.soinside.com 2019 - 2024. All rights reserved.