[英]How to remove modal-open class in Angular on new url?
I have a bootstrap modal in which there is a button upon clicking it will route the component (where the modal is present) to another component(questions).我有一个引导模式,其中有一个按钮,单击它会将组件(存在模式的位置)路由到另一个组件(问题)。 The problem is occuring when the new component is loaded the modal-open
class still remains in body
tag.加载新组件时出现问题, modal-open
class 仍保留在body
标记中。 Is there any way to remove the modal-body
?有什么方法可以删除modal-body
吗? Also if I click back to previous page the class still remains there.此外,如果我单击返回上一页,class 仍然存在。
modal code模态代码
<input type="submit" value="Submit" class="btn login-btn" [disabled]="profileForm.invalid" data-toggle="modal" data-target="#instructions">
<div class="modal fade" id="instructions" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalScrollableTitle">Instructions</h5>
</div>
<div class="modal-body">
content written here
<form action="">
<div class="form-row align-items-center">
<div class="col-auto my-1">
<div class="custom-control custom-checkbox mr-sm-2">
<input type="checkbox" class="custom-control-input" id="customControlAutosizing">
<label class="custom-control-label" for="customControlAutosizing">
To start, click the "Start" button. When finished, click the "Submit Quiz" button.
</label>
</div>
</div>
<div class="col-auto my-1">
<button type="submit" class="btn btn-primary" [routerLink]="['/questions']">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
I have written this css to override the main css but didn't worked:我写了这个 css 来覆盖主要的 css 但没有奏效:
.modal.fade .modal-dialog {
-webkit-transform: translate(0, -25%);
-ms-transform: translate(0, -25%);
transform: translate(0, -25%);
}
Also I tried to remove the fade
class from the modal
div.我还尝试从modal
div 中删除fade
class 。
in css put在 css 放
.hide{
display:none !important;
}
In your modal read display parameter在您的模态读取显示参数中
<div class="modal fade {{display}}" id="instructions" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
then give a click event to your button然后给你的按钮一个点击事件
<button type="submit" class="btn btn-primary"(click)="goToQuestion()">Submit</button>
and in component import router并在组件导入路由器中
import { Router } from '@angular/router';
in costrunctor put router and create display parameter在 costrunctor 中放置路由器并创建显示参数
display="";
constructor(private _router: Router) { }
and then write function然后写 function
goToQuestion(){
//here dismiss modal first then route
this.display="none";
this._router.navigate(['questions']);
}
In you submit button have data-dismiss="modal" and that should take care of the back drop在你提交按钮有 data-dismiss="modal" 并且应该照顾背景
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.