Twitter bootstrap 角度-在表单提交条件下显示引导模式

Twitter bootstrap 角度-在表单提交条件下显示引导模式,twitter-bootstrap,angular,Twitter Bootstrap,Angular,我有一个基于模型驱动方法的角度5形式。我已经进行了验证和填充,并进行了API调用。一旦api调用返回一个值,我就设置一个指示符true或false。基于这个返回值,我想显示一个指示结果的标准模式,如果成功,还需要清除表单内容。下面是我的代码: signup.component.html: <form [formGroup]="myForm" novalidate (ngSubmit)="register(myForm.value)" id="signUpForm" role="form"&

我有一个基于模型驱动方法的角度5形式。我已经进行了验证和填充,并进行了API调用。一旦api调用返回一个值,我就设置一个指示符
true
false
。基于这个返回值,我想显示一个指示结果的标准模式,如果成功,还需要清除表单内容。下面是我的代码:

signup.component.html

<form [formGroup]="myForm" novalidate (ngSubmit)="register(myForm.value)" id="signUpForm" role="form">
  <div class="row">
    <div class="col-lg-12 col-md-12">
      <div class="form-group">
        <input type="email" formControlName="email" placeholder="Enter Email..." class="form-control" aria-required="true">
      </div>
    </div>
  </div>
</form>
....
<div class="modal fade" [hidden]="!myForm.valid">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title">User Register</h5>
      </div>
      <div class="modal-body">
        <p>Signup done!</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
所以问题又来了:
1-即使值为真,模式也不会弹出。
2-一旦值变为true,我希望表单被重置。

要从组件打开bootrap modal,您需要声明

声明var$;
外部组件。然后,如果要在成功提交后显示模式,请使用
ViewChild

从'@angular/core'导入{ElementRef,ViewChild};
// ...
@ViewChild('someModal')someModal:ElementRef;
寄存器(型号:任意){
this.submitted=true;
// ...
$(this.someModal.nativeElement).modal('show');
}
至于从表单中删除值,您只需调用
this.myForm.reset()


你也可以考虑使用<强> <强> >

以上回答对我的角度为91.12

不起作用。 在我的项目中,我确实有很多其他的依赖项和东西,所以可能是一些我没有看到的问题。但这对我来说很有效:

  • private modalService:NgbModal
    添加到构造函数中

  • 添加表单变量,如

  • 添加元素访问器,如
    @ViewChild('askApprovalModal')askApprovalElementRef:ElementRef到你的.ts类

    open(content) {
     this.modalService.open(content);
    }
    
  • 添加一个按钮以触发条件以打开模式
    您的问题是什么?1-即使值为真,模态也不会弹出。2-一旦该值变为真,我希望表单被重置。@jbnize是否有任何帮助?
    
    open(content) {
     this.modalService.open(content);
    }
    
    f(){
     this.open(this.askApprovalElementRef)
    }