So I have this service with dummy data, and i wanted to add a field name called 'soeid' to this dummy list but it returns error
Error:
src/app/roaster-load/UploadService/upload.service.ts:10:3 - error TS2322: Type 'Observable<{ soeid: { SOEID: string; }[]; }>' is not assignable to type 'Observable<InvalidSOEIDModel[]>'. Type '{ soeid: { SOEID: string; }[]; }' is missing the following properties from type 'InvalidSOEIDModel[]': length, pop, push, concat, and 26 more.
upload.service.ts:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { InvalidSOEIDModel } from '../Uploadmodel/uploadmodel';
import { of } from 'rxjs';
@Injectable()
export class UploadService {
UploadDataReturn(): Observable<InvalidSOEIDModel[]> {
return of ( {
"soeid": [
{
SOEID: "AAAAA"
},
{
SOEID: "BBBBB"
}]
});
}
uploadmodel.ts:
export class InvalidSOEIDModel {
soeid!: SOEID[]
}
export class SOEID {
public SOEID!: string;
}
CodePudding user response:
If you just want it to return an array of InvalidSOEIDModel, this would be the code.
UploadDataReturn(): Observable<InvalidSOEIDModel[]> {
return of ( [{
"soeid": [
{
SOEID: "AAAAA"
},
{
SOEID: "BBBBB"
}]
}]);
If you just want InvalidSOEIDModel to return, this would be the code.
UploadDataReturn(): Observable<InvalidSOEIDModel> {
return of ( {
"soeid": [
{
SOEID: "AAAAA"
},
{
SOEID: "BBBBB"
}]
});