angular - 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}`);
}
);
}
当我尝试调用我的模态时,我总是遇到这个错误。
我的模式代码
<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>
我的模态组件代码
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>
推荐阅读
- quarkus-rest-client - 如何在 quarkus restAPI 中实现 angularjs
- apache-flink - Apache Flink 检查点卡住
- c++ - 使用 std::addressof(std::cout) 代替 &std::cout 有什么风险吗?
- maven - 当所有设置都正确时,Jenkins 自动部署失败。-- mapperLocations, Spring 中的错误 (illegalArgumentException, TomcatManagerException)
- php - Symfony 安装原则
- angular - 如何在使用 Renderer2 创建的元素上设置指令和属性绑定
- r - 在ggplot中为每个类的平均值添加红点
- c# - 如何使用 Task Async Await 从多个目录递归读取文件内容?
- algorithm - 什么是 LR(2) 解析器?它与 LR(1) 解析器有何不同?
- c# - 尝试连接到 Blazor 中的数据库但收到“MySql.Data.MySqlClient.Replication.ReplicationManager”错误