¿关闭一个ANGULAR 5形式的模态?

问题描述 投票:2回答:2

好吧,我希望当点击按钮时,模态关闭

enter image description here

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">&times;</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>
angular twitter-bootstrap bootstrap-modal
2个回答
4
投票

您可以使用@ViewChild来引用组件中的按钮:

  1. 添加对btn #btnClose的引用 <button #btnClose type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button>
  2. 在组件代码中创建@ViewChild @ViewChild('btnClose') btnClose : ElementRef
  3. 在提交函数中,qazxsw poi以编程方式输入btn qazxsw poi

0
投票
  1. 添加对bootstrap模式的引用。比如#exampleModals click
  2. 在组件中创建ViewChild。 crear(){ ... this.btnClose.nativeElement.click(); ... }
  3. 在明确的方法<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" #exampleModals>隐藏模态。 @ViewChild('exampleModals') exampleModals: ElementRef ;
© www.soinside.com 2019 - 2024. All rights reserved.