属性'app'在类型 'AppComponent' 上不存在



我刚开始使用CRUD应用程序。目的是使用下载按钮通过angular将mongoDB数据下载到Excel。在构建时,我收到了此错误
src/app/app.component.html:28:26中的错误-错误TS2339类型"AppComponent"上不存在属性"app"。

代码
app.component.html

<div>
<nav class="navbar navbar-expand navbar-dark bg-dark">
<a href="#" class="navbar-brand">HOME</a> #bezKoder
<div class="navbar-nav mr-auto">
<li class="nav-item">
<a routerLink="tutorials" class="nav-link">Tutorials</a>
</li>
<li class="nav-item">
<a routerLink="add" class="nav-link">Add</a>
</li>
</div>

<a style="cursor: pointer" (click)="exportexcel()">

</a>
</nav>
<div class="container mt-3">
<router-outlet></router-outlet>
</div>
</div>>
<table id="excel-table"> 
<tr>       
<th>title</th> 
<th>description</th>  

</tr>    
<tr *ngFor="let sup of app">
// This is the binding part. 
<td>{{ sup.title }}</td>  
<td>{{ sup.description }}</td> 
</tr> 

app.component.ts
import { Component } from '@angular/core';
import * as XLSX from 'xlsx'; 

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'Angular10Crud';
/*name of the excel-file which will be downloaded. */ 
fileName= 'tutorials_data.xlsx';  
exportexcel(): void 
{
/* table id is passed over here */   
let element = document.getElementById('excel-table'); 
const ws: XLSX.WorkSheet =XLSX.utils.table_to_sheet(element);
/* generate workbook and add the worksheet */
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
/* save to file */
XLSX.writeFile(wb, this.fileName);

}
}

错误消息非常不言自明。您在<tr *ngFor="let sup of app">中使用app,但在app.component.ts中没有名为app的属性。

你可能忘记把它放在那里了。因此,只需创建app属性(我假设它是一个数组(。

最新更新