[英]Object literal may only specify known properties Angular/TypeScript
I have an error message:我有一条错误消息:
Type '{ quantity: number; }' is not assignable to type
'Partial<EditOrderConfirmModalComponent>'.
Object literal may only specify known properties, and
'quantity' does not exist in type 'Partial<EditOrderConfirmModalComponent>'.
Error message - VSCode错误消息 - VSCode
I don't understand where is the problem?我不明白问题出在哪里?
The method is like this:方法是这样的:
open(): void {
const modalRef = this.modalService.show(EditOrderConfirmModalComponent, {
...NOT_CLOSABLE_MODAL_OPTIONS,
initialState: {
quantity: this.order!.quantity
}
});
modalRef.content!.closeModal.pipe(
takeUntil(this.unsubscribe$)
).subscribe(() => {
modalRef?.hide();
});
}
In the EditOrderConfirmModalComponent在 EditOrderConfirmModalComponent 中
I have this:我有这个:
export class EditOrderConfirmModalComponent implements OnInit {
modalService: any;
private unsubscribe$ = new Subject < void > ();
@Output() closeModal = new EventEmitter < void > ();
@Input() orderToEdit ? : Order;
constructor(
public modal: BsModalRef,
private router: Router,
private location: Location,
private service: EditOrderService
) {}
For HTML对于 HTML
<td style="min-width: 100%"> {{ orderToEdit.quantity }}</td>
Thank you for your time.感谢您的时间。
your initial state doesn't match the interface of the component.您的初始 state 与组件的接口不匹配。 you probably mean to do:
你可能打算这样做:
const modalRef = this.modalService.show(EditOrderConfirmModalComponent, {
...NOT_CLOSABLE_MODAL_OPTIONS,
initialState: {
orderToEdit: { quantity: this.order!.quantity }
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.