好吧,我希望当单击按钮时模式关闭
main.component.ts 在这里你也可以做点什么
crear(form){
this._servicio.creararchivos(this.formulario).subscribe(data =>{
this.conseguir();
form.reset();
this._routes.navigate(['/main']);
}, error =>{
console.log('error al crear el archivo');
}
);
我的html我认为这里的问题是需要一个按钮函数来执行我尝试使用Bostrap解雇但我不发送数据只是关闭我的点击
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog"
aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Subir Archivos</h5>
<button type="button" class="close" data-dismiss="modal" aria-
label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form (ngSubmit)="crear(a)" #a="ngForm" class="">
<div class="form-group">
<label for="user_id">User_id</label>
<!--<select class="form-control" id="exampleFormControlSelect1"
*ngFor="let
datos of archivo">-->
<input type="text" class="form-control" name="user_id"
[(ngModel)]="formulario.user_id">
<!-- </select> -->
</div>
<div class="form-group">
<label for="titulos">Titulo</label>
<input type="text" class="form-control" name="titulo"
[(ngModel)]="formulario.titulo">
</div>
<div class="form-group">
<label for="descripcion">Descripcion</label>
<input type="text" class="form-control" name="descripcion"
[(ngModel)]="formulario.descripcion">
</div>
<div class="form-group">
<label for="imagen">Imagen</label>
<input type="text" class="form-control" name="imagen"
[(ngModel)]="formulario.imagen">
</div>
<button type="submit" class="btn btn-primary" >SUBIR</button> //this <---
</form>
</div>
</div>
</div>
</div>
最佳答案
您可以使用@ViewChild
来引用组件中的按钮:
添加对 btn 的引用
#btnClose
<button #btnClose type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button>
在组件代码中创建一个
@ViewChild
@ViewChild('btnClose') btnClose : ElementRef
在提交函数中,以编程方式
单击
btncrear(){ ... this.btnClose.nativeElement.click(); ... }
关于angular - ¿关闭 ANGULAR 5 表单的模态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49100725/