【发布时间】:2020-09-21 13:10:56
【问题描述】:
我不熟悉 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);
}
}
【问题讨论】:
-
您可能在组件的某处引用了应用程序。
-
您没有在 component.ts 中定义应用程序属性。你只有 title 和 fileName 属性可用。