【问题标题】:Calling data from api and not display on fronted table but Its on the console in angular从 api 调用数据并且不显示在前置表上,但它在控制台上以角度显示
【发布时间】:2021-02-21 19:50:32
【问题描述】:

从 API 获取的数据没有显示在屏幕上,但我正在控制台中获取数据。

这是 .ts 文件。

export class VisibilityComponent implements OnInit {
  

  check = false;
  pmDetails1: IEmployee[];
  constructor( private userService: UserService) {
    this.pmDetails1 = [];
     }

  ngOnInit() {
  
     this.userService.getAllEmployee().subscribe((pmDetails1:       IEmployee[]) => {
      this.pmDetails1 = pmDetails1;
      console.log(this.pmDetails1);
    });


   }
   onItemChange(value) {
    if (value === '1' ) {
      this.check = true;
    } else {
      this.check = false;
    }
 }
 }
这是HTML文件
<div>
          <table class="table table-light" style="border: 1px solid">
            <thead style="background-color: aqua">
              <tr>
                <th>Select</th>
                <th>Name</th>
                <th>Role</th>
              </tr>
            </thead>
            <tbody>
              <tr
                *ngFor="let p of pmDetails1"
              >
                <td>
                  <input
                    type="checkbox"
                    value="{{ p.id }}"
                    [checked]="check"
                  />
                </td>
                <td>{{p.name}}</td>
                <td>{{p.role}}</td>
              </tr>
            </tbody>
          </table>
        </div>

这是控制台上的输出

请帮我解决这个问题。

【问题讨论】:

    标签: html asp.net angular typescript api


    【解决方案1】:

    您的数据不包含 idnamerole 元素。

    取而代之的是employeeIdemployeeNameemployeeRole。您需要更新您的表格代码。

    <td>
        <input
           type="checkbox"
           value="{{ p.employeeId }}"
           [checked]="check"
        />
    </td>
    <td>{{p.employeeName}}</td>
    <td>{{p.employeeRole}}</td>
    

    【讨论】:

    • 非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 2022-01-27
    • 2022-01-19
    • 2021-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多