Seeking assistance with creating dynamic pages for each object in the boxArray
file. I've developed a service called boxService
to extract objects. While I am able to retrieve all elements successfully, encountering errors when attempting to extract individual objects using the getDifferentBox
method:
TS2322: Type '<Observable null>;' is not assignable to type 'Observable<IBoxModel>'.<br/>Type 'null' is not assignable to type 'IBoxModel'.
TS2345: Argument of type 'IBoxModel | undefined' is not assignable to parameter of type 'IBoxModel'. Type 'undefined' is not assignable to type 'IBoxModel'.
Any insights on what could be going wrong? Appreciate your help.
boxService.ts
import { Injectable } from '@angular/core';
import {Observable, of} from "rxjs";
import {IBoxModel} from "../model/boxModel";
import {boxArray} from "../array/boxArray";
@Injectable({
providedIn: 'root'
})
export class BoxService {
getBoxes():Observable<IBoxModel[]>{
return of(boxArray)
}
getDifferentFox(id: string):Observable<IBoxModel> {
return of<IBoxModel>(boxArray.find( value => value.id === + id ) )
}
}
boxArray.ts
import {IBoxModel} from "../model/boxModel";
export const boxArray: IBoxModel[] = [
{ id: 1,
title: "Бокс номер 1",
address: 0o1515,
}
{ id: 2,
title: "Бокс номер 2",
address: 0o1519,
}]
boxModel.ts
export interface IBoxModel {
id: number;
title: string;
address: number;
}