我有ts中的数据,我需要在Angular4 html中获取该数据,但我只能获取2个循环外的数据。任何人都可以帮我在angular4中获取数据。
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:
this.service
.getProfileData(id)
.subscribe(
data => {
this.accepts = data;
console.log(this.accepts);
}, error => {})
安慰输出:
答案 0 :(得分:1)
呈现的某些字段是错误的,确保密钥存在于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>
答案 1 :(得分:1)
这可能会有所帮助
myMaximumBySum [] = [] -- degenerate case
myMaximumBySum [x] = x -- tautological case
myMaximumBySum (x:xs)
| sum x > sum (myMaximumBySum xs) = x
| otherwise = myMaximumBySum xs
-- or more naturally:
myMaximumBySum = foldr f []
where f x acc = if sum x > sum acc then x else acc