每當(dāng)我嘗試創(chuàng)建新票時(shí),都會(huì)收到以下錯(cuò)誤消息:無(wú)法讀取未定義的屬性“id”這是我的 thread.service.ts,其中有用于創(chuàng)建票證的 AddTicket 方法: addTicket(id: string,heading: string,user: string,date: Date,description: string,likeCount: number,timeLeft: number){ const newTicket = new Threads ( id, heading, user, new Date(date), description, likeCount, timeLeft ); let generatedId: string; return this.http .post<{ name: string }>( 'https://ionic-angular-a0570.firebaseio.com/all-tickets.json', { ...newTicket, id: Math.random().toString() } ) .pipe( switchMap(resData => { generatedId = resData.name; return this.tickets; }), take(1), tap(tickets => { newTicket.id = generatedId; this._tickets.next(tickets.concat(newTicket)); }) );}我正在調(diào)用 new-thread.page.ts 中的方法: onCreateTicket(){this.threadService.addTicket(this.threads.id, this.heading, this.registerService.user, this.threadService.getDate(), this.description, +this.threadService.getLikes(), +12).subscribe();如果有幫助,這是我的threads.model.ts:export class Threads {constructor( public id: string, public heading: string, public user: string, public date: Date, public description: string, public likeCount: number, public timeLeft: number){}}新線(xiàn)程.page.ts:import { Component, OnInit } from '@angular/core';import { ThreadsService } from '../main/departmentforum/threads/threads.service';import { NavController } from '@ionic/angular';import { RegisterService } from '../register/register.service';import { Threads } from '../main/departmentforum/threads/threads.model';@Component({ selector: 'app-new-thread', templateUrl: './new-thread.page.html', styleUrls: ['./new-thread.page.scss'],})export class NewThreadPage implements OnInit { heading: string; description: string; businessforum: string; departmentforum: string; threads: Threads; constructor(private navController: NavController, private threadService: ThreadsService, public registerService: RegisterService) {} ngOnInit() { }
Angular - 無(wú)法讀取未定義的屬性“id”
阿波羅的戰(zhàn)車(chē)
2022-05-14 15:22:09