如何解决在NgbModal上未定义ComponentInstace
自昨天晚上以来,我一直在想着为什么这段代码不起作用
onOutletFeedback(content) {
const modalRef = this.modalService.open(content,{
scrollable: false,size: 'md'
});
modalRef.componentInstance.contactId = this.contactId; //Facing issue at this line
modalRef.componentInstance.url = environment.apiUrl;
modalRef.result.then(
result => {
// on save click
},reason => {
// on dismiss
console.log(`Dismissed with: ${reason}`);
}
);
}
当我尝试调用我的Modal时,总是会收到此错误。
我的模态代码
<button (click)="onOutletFeedback(OutletFeedbackModal)"
class="btn btn-secondary"
placement="bottom"
ngbTooltip="Feedback" >
<i class="icon-comment"></i></button>
<ng-template #OutletFeedbackModal let-modal>
<app-outlet-feedback [modal]="modal"></app-outlet-feedback>
</ng-template>
我的ModalComponent代码
export class OutletFeedbackComponent implements OnInit {
@Input() modal: any;
@Input() contactId: number;
感谢您的帮助,我已经检查了文档和所有可能的链接。
解决方法
您可以直接将输入属性值分配给app-outlet-feed尝试以下方法:
<ng-template #OutletFeedbackModal let-modal>
<app-outlet-feedback [contactId]="contactId" [modal]="modal"></app-outlet-feedback>
</ng-tempalte>
,
根据文档,这是使用ngdModal将数据传递到内容的方法:
this.modalRef['data'] = "any data you want to pass to ModalComp class";
PS:'componentInstance'是角度测试API的一部分。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。