Всякий раз, когда я пытаюсь создать новый тикет, я получаю это сообщение об ошибке:
Невозможно прочитать свойство 'id' из неопределенного
Это мой thread.service .ts, где у меня есть метод 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));
})
);
}
И я вызываю метод в 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
){}}
new-thread.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() {
}
onCreateTicket(){
this.threadService.addTicket(this.threads.id, this.heading, this.registerService.user, this.threadService.getDate(), this.description, +this.threadService.getLikes(), +12).subscribe();
this.navController.navigateBack('main/departmentforum/threads');
}
}
thread.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
){}}