输入 '{ componentParent: this; }' 与类型 'Partial<RegisterEnterpriseComponent>' angular 没有共同的属性
Type '{ componentParent: this; }' has no properties in common with type 'Partial<RegisterEnterpriseComponent>' angular
我正在使用 angular 10,我试图在我的组件中显示模态,但出现此错误:
Type '{ componentParent: this; }' has no properties in common with type 'Partial<RegisterEnterpriseComponent>'
代码:
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
bsModalRef: BsModalRef;
constructor(
public modalService: BsModalService, public mybsModalRef: BsModalRef) {
}
openModal(id) {
const initialState = {
componentParent: this
};
this.bsModalRef = this.modalService.show(RegisterEnterpriseComponent, {initialState}); // The error is in this line
this.bsModalRef.setClass('modal-lg');
this.EnterpriseService.closeModal = this.bsModalRef;
}
我以前在 angular 8 中使用过此功能,但我不知道为什么在 angular 的这个版本中不起作用...
谁能帮我解决这个问题?
谢谢!
问题已解决。
如果有人面临同样的问题,在较新版本的 ngx-bootstrap 中,所需的参数不再需要 initialParent:
我不得不这样说:
this.bsModalRef = this.modalService.show(RegisterEnterpriseComponent);
而且它没有任何问题。
您只能指定您用于模态的 RegisterEnterpriseComponent
组件上实际存在的属性,因此如果您的 RegisterEnterpriseComponent
组件包含 this.modalRef = this.modalService.show(RegisterEnterpriseComponent, { initialState: {test: ''} });
则不会报错 属性 test
.
const config = {
class: 'modal-dialog-centered',
initialState: {
id,
name: this.productTypes.find((p) => p.id === id).name,
},
};
//show modal
this.bsModalRef = this.modalService.show(
AddModalProductTypeComponent,
config
);
//get data in modal
export class AddModalProductTypeComponent implements OnInit {
@Output() newProductType = new EventEmitter<any>();
id: number;
name: string;
}
我正在使用 angular 10,我试图在我的组件中显示模态,但出现此错误:
Type '{ componentParent: this; }' has no properties in common with type 'Partial<RegisterEnterpriseComponent>'
代码:
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
bsModalRef: BsModalRef;
constructor(
public modalService: BsModalService, public mybsModalRef: BsModalRef) {
}
openModal(id) {
const initialState = {
componentParent: this
};
this.bsModalRef = this.modalService.show(RegisterEnterpriseComponent, {initialState}); // The error is in this line
this.bsModalRef.setClass('modal-lg');
this.EnterpriseService.closeModal = this.bsModalRef;
}
我以前在 angular 8 中使用过此功能,但我不知道为什么在 angular 的这个版本中不起作用...
谁能帮我解决这个问题?
谢谢!
问题已解决。
如果有人面临同样的问题,在较新版本的 ngx-bootstrap 中,所需的参数不再需要 initialParent:
我不得不这样说:
this.bsModalRef = this.modalService.show(RegisterEnterpriseComponent);
而且它没有任何问题。
您只能指定您用于模态的 RegisterEnterpriseComponent
组件上实际存在的属性,因此如果您的 RegisterEnterpriseComponent
组件包含 this.modalRef = this.modalService.show(RegisterEnterpriseComponent, { initialState: {test: ''} });
则不会报错 属性 test
.
const config = {
class: 'modal-dialog-centered',
initialState: {
id,
name: this.productTypes.find((p) => p.id === id).name,
},
};
//show modal
this.bsModalRef = this.modalService.show(
AddModalProductTypeComponent,
config
);
//get data in modal
export class AddModalProductTypeComponent implements OnInit {
@Output() newProductType = new EventEmitter<any>();
id: number;
name: string;
}