【问题标题】:Disable Button on Page Load页面加载时禁用按钮
【发布时间】:2020-12-21 21:12:01
【问题描述】:

我有一个网页正在加载要从中选择并添加到列表中的项目列表。我想做的是拥有它,这样当用户搜索一个项目并单击搜索时,任何加载并已经在用户选定项目列表中的项目都将禁用其按钮。当用户单击该项目时,我可以禁用按钮,但是如果他们搜索相同的项目,则该按钮将再次可单击

body.component.html 中的按钮代码:

<button type="submit" *ngIf="!checkNominations(mov)" (click)="nominate(mov, $event)">Nominate</button>

body.component.ts 中检查/禁用按钮的代码:

  nominate(mov: string, event:any){
    this.nominations.push(mov);
    event.target.disabled = true;
  }

  checkNominations(mov: Object){
    return this.nominations.indexOf(mov) !== -1;
  }

【问题讨论】:

    标签: angular


    【解决方案1】:

    设法以不同的方式解决它,如果有人知道如何提高效率,我将不胜感激!

    body.component.html 中的按钮代码:

    <button type="submit" *ngIf="!checkNominations(mov)" (click)="nominate(mov)">Nominate</button>
            <button type="submit" *ngIf="checkNominations(mov)" disabled="True">Nominated!</button>
    

    body.component.ts 中检查/禁用按钮的代码:

    checkNominations(mov: Object){
        let arr = [];   
        arr.push(mov);
        var isInArray = this.nominations.find(e => e.Title === arr[0].Title) !== undefined;
        return isInArray;
      }
    

    【讨论】:

      猜你喜欢
      • 2021-12-23
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 2017-01-12
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多