我创建的应用程序在开发服务器上(ng serve)运行良好,但是当我尝试构建生产版本时,它会出现以下错误
我的应用程序在开发服务器上运行正常,但是当我试图构建生产版本时,出现了这个错误。
ERROR in src/app/leaderboard/leaderboard.component.html(9,17): Argument of type 'object' is not assignable to parameter of type 'Map<unknown, unknown>'
这是我的 leaderboard.component.ts 文件
import { Component, OnInit } from '@angular/core';
import * as firebase from 'firebase/app';
import 'firebase/firestore';
@Component({
selector: 'app-leaderboard',
templateUrl: './leaderboard.component.html',
styleUrls: ['./leaderboard.component.css']
})
export class LeaderboardComponent implements OnInit {
constructor() { }
db = firebase.firestore();
cities:object;
suburbs:object;
unsorted() { }
async getCities() {
await this.db.collection("Cities").orderBy('count', "desc").get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
//console.log(doc.id, ": ", doc.data().count);
this.cities[doc.id] = doc.data().count
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
}
async getSuburbs() {
await this.db.collection("Suburbs").orderBy('count', "desc").get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
//console.log(doc.id, ": ", doc.data().count);
this.suburbs[doc.id] = doc.data().count
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
}
ngOnInit() {
this.getCities()
this.getSuburbs()
}
}
这是leaderboard.component.html文件
<div class="container">
<div class="row">
<h3>Cities</h3>
<table class="table">
<thead class="thead-dark">
<th scope="col">City</th>
<th scope="col">Bears found</th>
</thead>
<tr *ngFor="let city of cities | keyvalue: unsorted">
<td>{{city.key}}</td>
<td>{{city.value}}</td>
</tr>
</table>
</div>
<div class="row">
<h3>Suburbs</h3>
<table class="table">
<thead class="thead-dark">
<th scope="col">Suburb</th>
<th scope="col">Bears found</th>
</thead>
<tr *ngFor="let suburb of suburbs | keyvalue: unsorted">
<td>{{suburb.key}}</td>
<td>{{suburb.value}}</td>
</tr>
</table>
</div>
</div>
我认为这是TypeScript的某种打字错误,但由于我只是一个初学者,不太确定我能做什么来修复它。
我已经忽略了第二个错误,因为它与我在第9行使用keyvalue管道时出现的错误相同。
谢谢
unsorted() { }
方法是空的。 - Kiran Mistry