angular - ¿关闭 ANGULAR 5 表单的模态?

标签 angular twitter-bootstrap bootstrap-modal

好吧,我希望当单击按钮时模式关闭

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>

最佳答案

您可以使用@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. 在提交函数中,以编程方式单击 btn

    crear(){
    ...
        this.btnClose.nativeElement.click();
    ...
    }
    

关于angular - ¿关闭 ANGULAR 5 表单的模态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49100725/

相关文章:

angular - 检查material2 sidenav是否打开

jquery - 我如何添加 jquery ui 日期选择器,同时已经在使用 Bootstrap 库?

html - 带有 css 和 bootstrap 的菜单中的两行

javascript - Bootstrap 3 - 最大化窗口时导航对齐未正确显示

javascript - 如果用户在聊天机器人外部单击,如何添加触发关闭聊天机器人?

Angular 2 Quickstart - 我的应用程序组件未加载

angular - $在Angular 7中是什么意思

angular - 如何将随机类分配给 *ngFor 在 DOM 中生成的元素?

twitter-bootstrap - 如何在移动设备的 Bootstrap 模式上正确显示 reCAPTCHA?

javascript - CKEditor激活时如何显示占位符