首页 > 解决方案 > div[id]=function 不能调用相应的打字稿函数?

问题描述

我需要将 Employee 值列表从 html 传递给 typescript 函数。我需要根据 typescript 中的五个条件更改员工交易记录的图像,为此我正在使用 Div [id]=function.The 函数根据条件返回相应的 css 类名称。由于我有 5 个条件,我无法使用 ngif,另外我需要传递员工列表。上面的 html 代码也有一个员工列表列表,我已经在上面循环。问题是在 html 中声明的这个函数没有调用相应的 ts 函数。所以请告诉我该方法是否正确或需要更改。

**HTML**
       <div [id]="getEmployeeId(Employee)">
        <div id="h31">
        <em class="" style="font-size: 0.7rem;font-weight: bold;"></em>
        </div>
       </div>
**TS**
getEmployeeId(Employee) {
  
    for (var EmployeeList of Employee){
        if ((EmployeeList.EmployeeStatus== 'Active')  {
          this.inputDisabled = false;
          return 'circle3'; //noicon 
        }
        else if ((EmployeeList.IsEmpty== true) {
          this.inputDisabled = true;
          return 'circle4'; //orange
        }
        else if (EmployeeList.Employeestatus == 'Error') {
          this.inputDisabled = true;
          return 'circle6'; //red
        }
        else if (EmployeeList.transactionStatus == 'Completed') {
          this.inputDisabled = true;
          return'circle2'; //green
        }
        else if (EmployeeList.transactionStatus == 'Screened')  {
          this.inputDisabled = true;
          return 'circle5'; //blue
        }
      }
  
  }


**CSS**

 #circle2{
  width: 24px;
  height: 24px;
  margin: 5px 25px;
  border-radius: 30px;
  margin-right: 15px;
  background: #a9d18e;
  display: flex;


 

标签: angular

解决方案


推荐阅读