Html 角度:从onClick事件按钮向输入添加值
我正在尝试使用Angular创建编辑模式。td字段从此表中获取一个值,并使用(单击)事件将其发送到模式 这是一个模式,我要在这里得到值Html 角度:从onClick事件按钮向输入添加值,html,angular,typescript,Html,Angular,Typescript,我正在尝试使用Angular创建编辑模式。td字段从此表中获取一个值,并使用(单击)事件将其发送到模式 这是一个模式,我要在这里得到值 <ng-template #contenido let-modal> <div class="modal-header"> <h4 class="modal-title">Editar datos de mascota</h4> <button cl
<ng-template #contenido let-modal>
<div class="modal-header">
<h4 class="modal-title">Editar datos de mascota</h4>
<button class="close" aria-label="close" type="button" (click)="modal.close()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form class="form-horizontal form-material" id="editform" autocomplete="off">
<div class="form-group m-t-10">
<div class="col-sm-10">
<label>Nombre de Mascota:</label>
<input class="form-control" type="text" placeholder="Nombre" value="mascota.name" />
</div>
</div>
</form>
</div>
</ng-template>
马斯科塔达托斯酒店
&时代;
名称:马斯科塔:
但当我点击编辑按钮时,它无法识别该值
当我使用{{}时,常量得到一个“未定义”的值
有没有办法获取该值并将其放入输入标记中?我想对其他td领域也这么做,但首先这需要很好地工作
您能分享
contenido
数据吗?还有一个猜测value=“{{mascota?.name}}”
我上传了存储在const modalRef中的contenido数据(第二幅图像);我还尝试了{mascota?.name},未定义的错误消失了,但该值仍然为空,记录模态构造函数中的输入,并检查您接收到的操作,您可以在第3张图片上看到,使用“mascota”参数,我得到了我想要的数据,有没有办法从模式调用它?打开后,您将mascota
分配给model
。我建议您传递数据this.modal.open({contenido,mascota},{size:'lg',centered:true})代码>像这样,然后尝试相应地访问它。
openSM(contenido, mascota) {
const modalRef = this.modal.open(contenido,{size:'lg',centered:true});
modalRef["mascota"] = mascota;
console.log(modalRef);
}
<ng-template #contenido let-modal>
<div class="modal-header">
<h4 class="modal-title">Editar datos de mascota</h4>
<button class="close" aria-label="close" type="button" (click)="modal.close()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form class="form-horizontal form-material" id="editform" autocomplete="off">
<div class="form-group m-t-10">
<div class="col-sm-10">
<label>Nombre de Mascota:</label>
<input class="form-control" type="text" placeholder="Nombre" value="mascota.name" />
</div>
</div>
</form>
</div>
</ng-template>