angular4 *ngIf 判断对象数组是否为空
判断对象
"downloadinfo": [ { "downtype": "16", "linkvalue": "https://pan.baidu.com/s/1kVutjX9", "fetchcode": "", "remark": "", "ico": "http://i1.fuimg.com/588755/7dcc4108ce360c2a.png" } ]
模板代码
<div *ngIf="isEmptyObject(downloadinfo); else templateName">downloadinfo不为空</div> <ng-template #templateName>downloadinfo为空</ng-template>
组建代码
public isEmptyObject(obj) { //console.log(obj.length); return obj.length; }
分析
当downloadinfo为空,即: "downloadinfo": []时, obj.length为0.