1
我已經通過this post(和this one以及)找到我的問題的解決方案。Ionic3,Typescript - 忽略Typescript錯誤「屬性」在類型''的值不存在
我想忽略這些錯誤:
Property 'payload' does not exist on type 'Matatu'.
Property 'key' does not exist on type 'Matatu'.
我試圖聲明變量「覆蓋」的類型系統,但並未奏效。
這裏是我的.ts
代碼,是我到目前爲止已經嘗試:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ActionSheetController } from 'ionic-angular';
import { AngularFireList, AngularFireDatabase } from 'angularfire2/database';
import { Matatu } from '../../models/matatu/matatu.interface';
/* imports */
declare var payload;
declare var key;
@IonicPage()
@Component({
selector: 'page-owner-dash',
templateUrl: 'owner-dash.html',
})
export class OwnerDashPage {
matatuListRef$: AngularFireList<Matatu>;
matatuListAsync$: any;
constructor(public navCtrl: NavController, public navParams: NavParams, private database: AngularFireDatabase, public actionShtCrtl: ActionSheetController) {
this.matatuListRef$ = this.database.list('matatu-list');
this.matatuListAsync$ = this.matatuListRef$.snapshotChanges();
}
ionViewDidLoad() {
//stuff
}
selectMatatu(matatu: Matatu){
this.actionShtCrtl.create({
title: `${matatu.payload.val().matNumberPlate}`,
buttons: [
{
text: 'Edit',
handler:() => {
//stuff
}
},
{
text: 'Delete',
role: 'destructive',
handler:() => {
this.matatuListRef$.remove(matatu.key);
}
},
{
text: 'Cancel',
role: 'cancel',
handler:() => {
//do something
}
}
]
}).present();
}
}
這裏的Matatu
結構:
export interface Matatu {
$key?: string;
matNumberPlate: string;
matSacco: string;
matDriver: string;
matAccessCode: string;
matStatus: string;
matTracker: string;
matLocation: string;
}
我怎麼投的財產,以任何類型?
請問您還可以添加「Matatu」類型的定義嗎? – sebaferreras
這是一個界面。它是。 – kenyami