【问题标题】:how to write *(star) program in angular 2+如何用 Angular 编写 *(star) 程序 2+
【发布时间】:2020-04-08 03:05:15
【问题描述】:

在 Angular 2+ 中编写代码

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

例如。

单击 1 - 输出为 *

单击 2 - 输出为 **

单击 3 - 输出为 ***

【问题讨论】:

    标签: html angular typescript ngfor


    【解决方案1】:

    只需在触发点击事件后附加“*”即可:

    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

    【讨论】:

      猜你喜欢
      • 2018-08-02
      • 2011-03-23
      • 2023-03-23
      • 2017-12-29
      • 2020-01-01
      • 1970-01-01
      • 2016-12-22
      • 2016-08-23
      • 2016-09-30
      相关资源
      最近更新 更多