简体   繁体   English

如何在Angular4中获取数据进入控制台进入HTML

[英]How to fetch data getting in console to HTML in angular4

I have data in ts, i need to fetch that data inside the Angular4 html, but i am able to fetch only 2 data which are outside the loop. 我在ts中有数据,我需要在Angular4 html中获取该数据,但是我只能获取2个不在循环之外的数据。 Can anyone help me to fetch data inside angular4. 谁能帮我在angular4内部获取数据。

HTML: HTML:

              <tr *ngFor="let accept of accepts">
                <td>{{accept.name}}</td>
                <td>{{accept.description}}</td>
                <td>{{accept.daterecv}}</td>
                <td>{{accept.dateacc}}</td>
                <td>{{accept.deadline}}</td>
                <td>{{accept.price}}</td>
                <td>{{accept.status}}</td>
                <td>{{accept.due_date}}</td>
              </tr>
            </tbody>

Ts: Ts:

this.service
            .getProfileData(id)
            .subscribe(
              data => {
                this.accepts = data;
                console.log(this.accepts);
              }, error => {})

Consoled Output: 控制台输出:

在此处输入图片说明

Some of the fields rendered are wrong,make sure the keys are present in the data in the ts also use safe navigation operator to make sure data is present, it should be as 呈现的某些字段是错误的,请确保ts中的数据中存在键。还请使用安全的导航操作符来确保数据存在,应

<tr *ngFor="let accept of accepts">
            <td>{{accept?.Job?.User?.name}}</td>
            <td>{{accept?.user?.description}}</td>
            <td>{{accept?.Job?.price}}</td>
            <td>{{accept?.Job?.status}}</td>
            <td>{{accept?.Job?.due_date}}</td>
</tr>

This might help 这可能有帮助

 <tr *ngFor="let accept of accepts">
            <td>{{accept?.Job?.User?.name}}</td>
            <td>{{accept?.Job?.description}}</td>
            <td>{{accept?.Job?.deadline}}</td>
            <td>{{accept?.Job?.price}}</td>
            <td>{{accept?.Job?.status}}</td>
            <td>{{accept?.Job?.due_date}}</td>
          </tr>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM