提问人:mohciniya 提问时间:2/11/2022 最后编辑:mohciniya 更新时间:2/11/2022 访问量:668
core.mjs:6484 错误 TypeError:无法读取未定义的属性(读取“QTY”)
core.mjs:6484 ERROR TypeError: Cannot read properties of undefined (reading 'QTY')
问:
我在控制台中有一条错误消息,但我不明白问题出在哪里。
股票观察.ts
export interface StockWatch {
svm: number;
ticker: string;
name: string;
buy: {
qty: number;
limit: number;
},
volume: number;
last: number;
}
股票观察.response.ts
import { ApiResponse } from "src/app/shared/types/api.response";
export interface StockWatchResponse extends ApiResponse {
STOCKWATCH: {
ELEMENT: {
CODE: string;
ISIN: string;
SVM: number;
LABEL: string;
CURRENCY: string;
REALTIME: string;
LASTPRICE: number;
DATELASTPRICE: string;
TIMELASTPRICE: string;
PLACE: number;
PLACELABEL: string;
ALERTE: string;
PRICEVARIATIONPRC: number;
PRICEVARIATIONNOM: number;
PRICEVARIATIONCUR: string;
VOLUME: number;
ACHTEUR1: AchtVend;
VENDEUR1: AchtVend;
}[];
}
}
export interface AchtVend {
NUMBRE: number;
QTY: number;
COURS: number;
}
股票观察.service.ts
@Injectable()
export class StockWatchService {
private readonly api: string = environment.api;
constructor(private http: HttpClient, private store: Store) { }
getStockWatch(showBusy: boolean): Observable<StockWatchResponse> {
let headers = new HttpHeaders();
headers = headers.set('AddCustomer', '');
if (!showBusy) {
headers = headers.set('DoNotSetBusy', '');
}
return this.http.post<StockWatchResponse>(this.api + `/AZERTY`, {
ACTION: "DSP",
SVM: 0
}, { headers });
}
}
股票观察.component.ts
我认为问题出在方法上?getStockWatch
export class StockWatchComponent implements OnInit, OnDestroy {
private unsubscribe$ = new Subject<void>();
lines: StockWatch[] = [];
gotResponse: boolean = false;
private unsubscribeTimer$ = new Subject<void>();
timer: number = -1;
constructor(private service: StockWatchService) { }
ngOnInit(): void {
this.getStockWatch(true);
this.startTimerStock();
}
ngOnDestroy(): void {
this.resetSubscriptions(false);
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
refresh(): void {
this.resetSubscriptions();
this.getStockWatch(false);
this.startTimerStock();
}
private resetSubscriptions(recreate: boolean = true): void {
this.unsubscribeTimer$.next();
this.unsubscribeTimer$.complete();
if (recreate) {
this.unsubscribeTimer$ = new Subject<void>();
}
this.timer = -1;
}
private getStockWatch(showBusy: boolean): void {
this.gotResponse = false;
this.service.getStockWatch(showBusy).pipe(
finalize(() => this.timer = 30),
takeUntil(this.unsubscribe$)
).subscribe(res => {
this.gotResponse = true;
this.lines = res.STOCKWATCH.ELEMENT.map(x => {
return {
svm: x.SVM,
ticker: x.CODE,
name: x.LABEL,
buy: {
qty: x.ACHTEUR1.QTY,
limit: x.ACHTEUR1.COURS
},
volume: x.VOLUME,
last: x.LASTPRICE
}
});
});
}
private startTimerStock(): void {
timer(0, 1000).pipe(
filter(() => this.timer >= 0),
takeUntil(this.unsubscribeTimer$)
).subscribe(() => {
this.timer -= 1;
if (this.timer < 0) {
this.getStockWatch(false);
}
});
}
}
编辑
答: 暂无答案
评论
this.lines = res.STOCKWATCH.ELEMENT.map(x => {...
ACHTEUR1
VENDEUR1
QTY