angular - Angular - Value not being passed to Modal view
问题描述
I am trying to pass through a value to a modal component, I followed this tutorial: https://itnext.io/creating-forms-inside-modals-with-ng-bootstrap-221e4f1f5648.
I can see the value being passed through, but not being retained on the other side. Any ideas why?
// Component being sent from
openModal(millerIndex: number, farmIndex: number, view: number, millerName: string) {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.millerIndex = millerIndex;
modalRef.componentInstance.farmIndex = farmIndex;
modalRef.componentInstance.view = view;
modalRef.componentInstance.millerName = millerName;
modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}
// Modal component with relevant imports
@Input() millerIndex: number;
@Input() farmIndex: number;
@Input() view: number;
@Input() millerName: string;
@Input() farmName: string;
modalTitle = '';
// Being called OnInit()
createForm() {
if (this.view === 1) {
this.myForm = this.formBuilder.group({
paddockCode: new FormControl('', Validators.required),
paddockArea: new FormControl('', Validators.required),
paddockOwner: new FormControl({value: this.farmName, disabled:
true}, Validators.required)
});
}
// HTML inside form
<div class="form-group">
<label for="paddock-owner">Owner</label>
<input type="text" class="form-control"
formControlName="paddockOwner" value="{{ farmName }}" />
</div>
解决方案
正如上面提到的戴尔,我没有通过farmName。
openModal(millerIndex: number, farmIndex: number, view: number,
millerName: string, farmName: string) {
const modalRef = this.modalService.open(ModalComponent);
modalRef.componentInstance.millerIndex = millerIndex;
modalRef.componentInstance.farmIndex = farmIndex;
modalRef.componentInstance.view = view;
modalRef.componentInstance.millerName = millerName;
modalRef.componentInstance.farmName = farmName;
modalRef.result.then((result) => {
console.log(result);
}).catch((error) => {
console.log(error);
});
}
推荐阅读
- php - 带有 php 的 youtube 视频下载器
- android - 当Android应用程序处于后台/关闭时未调用onNotification
- javascript - 仅在先前获取成功后使用 useEffect / useState 设置异步数据获取超时的正确方法
- java - 在 IntelliJ 和 geany 中运行项目有区别吗?
- android - 实施华为移动服务
- d3.js - dc.js 系列图表 - 填充缺失数据时图表太慢
- javascript - 一次通过 JS 发送表单和常规 POST
- javascript - 在嵌套的 for 循环中进行 fetch 调用
- oracle - 在 Azure 上配置 Oracle 虚拟机
- sql - 我该怎么做呢 ?时间间隔