属性 'app' 在类型 'AppComponent' 上不存在
Property 'app' does not exist on type 'AppComponent'
我是 angular 开发 CRUD 应用程序的新手。目的是使用下载按钮通过 angular 将 mongoDB 数据下载到 Excel。在构建它时,我收到此错误
src/app/app.component.html:28:26 中的错误 - 错误 TS2339 属性 'app' 在类型 'AppComponent'.
上不存在
代码
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);
}
}
错误信息很漂亮self-explanatory。您在 <tr *ngFor="let sup of app">
中使用 app
,但在您的 app.component.ts
.
中没有名为 app
的 属性
你可能忘了把它放在那里。所以只需创建 app
属性 (我假设它是一个数组)。
我是 angular 开发 CRUD 应用程序的新手。目的是使用下载按钮通过 angular 将 mongoDB 数据下载到 Excel。在构建它时,我收到此错误
src/app/app.component.html:28:26 中的错误 - 错误 TS2339 属性 'app' 在类型 'AppComponent'.
代码
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);
}
}
错误信息很漂亮self-explanatory。您在 <tr *ngFor="let sup of app">
中使用 app
,但在您的 app.component.ts
.
app
的 属性
你可能忘了把它放在那里。所以只需创建 app
属性 (我假设它是一个数组)。