Javascript 在数据库中未找到搜索结果时显示消息
Javascript 在数据库中未找到搜索结果时显示消息,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,this.searchError即使docCheck.id不等于null也会显示 我已尝试设置搜索的result.length是否等于零以显示错误消息 但是,我从控制台data.map错误 filterDocument(customerId: number, from: string, to: string, criterion: string) { this.filteredDocument = []; this.searchError = '';
this.searchError
即使docCheck.id
不等于null也会显示
我已尝试设置搜索的result.length
是否等于零以显示错误消息
但是,我从控制台data.map错误
filterDocument(customerId: number, from: string, to: string, criterion: string) {
this.filteredDocument = [];
this.searchError = '';
this.documentService.getDocuments(customerId, privateDoc, from, to,
criterion).subscribe(
data => {
if(this.docCheck.id == null){
this.searchError ='No search related document found';
console.log('No related search found')
}
this.showspinner = false;
data.map(item => {
this.filteredDocument.push(item);
console.log('this is the data from filter:', data);
});
this.showspinner = false;
},
error1 => {
this.swalWithBootstrapButtons.fire(
'Error!',
'Error inesperado al mostrar el filtro.',
'error'
);
});
// this.documents = this.filteredDocument;
}
}
HTML-表格显示
<div *ngIf="!showspinner && searchError" class="card">
<div class="card-header notification py-3">
<span class="font-weight-bold text-dark">{{searchError}}</span>
</div>
</div>
<table *ngIf="!showspinner && filteredDocument.length>0">
<thead>
<tr class="bg-primary text-white" >
<th class="text-left" scope="col">Date Registration</th>
<th class="text-left" scope="col">Title of Document</th>
</tr>
</thead>
<tbody *ngFor="let doc of filteredDocument">
<tr>
<td class="text-left">{{doc.date | date: 'dd-MM-yyyy'}}</td>
<td class="text-left" [title]="doc.name ? doc.name : ''">{{doc.name}}
<!--<b>{{(doc.name) ? (doc.name | slice:0:45) + '...' : (doc.date)}}</b>-->
<span *ngIf="!doc.name">-----</span>
</td>
</tr>
</tbody>
</table>
{{searchError}}
登记日期
文件标题
{{doc.date}date:'dd-MM-yyyy'}
{{doc.name}
-----
对stackblitz进行最少的复制,显示更多代码,显示准确的错误。但是现在很难知道模板是什么样子的?我假设您在doCheck.id上使用*ngIf,请将代码与您分享。我添加了code@Augustine仍然没有足够的代码来跟踪错误。this.docCheck
set在哪里?