如何清除角度2中​​的bootstrap默认模态的内容

时间:2017-12-07 03:32:27

标签: angular

我的模态中有一些输入元素,当我输入内容并重新打开模态时它不会重置它。我可以在每次打开它时刷新模态内容。

每次重新打开模态时,如何重置表单元素。

<li class="top-button"> <a data-toggle="modal" data-target="#signup_modal" class="btn-custom btn" (click)="closemo()">Sign Up</a>

<div class="modal fade" id="signup_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div  class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"    #closeBtnReg><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Sign Up</h4>
                </div>
                <div class="modal-body">
                    <div class="">
                        <div class="">
                            <div class="">
                                <div class="panel-heading"> </div>
                                <div class="panel-body">
                                    <form (ngSubmit)="register(customerregisterForm)" #customerregisterForm="ngForm" novalidate>
                                        <fieldset>
                                            <div class="form-group">
                                                <input type="text" class="form-control" id="signup_name" placeholder="Name" [(ngModel)]=" signup_name" name="signup_name" minlength="3" maxlength="30" #titlename="ngModel"  required>
                                                <div *ngIf="titlename.errors && (titlename.dirty || titlename.touched)" class="alert alert-danger">
                                                    <div [hidden]="!titlename.errors.required">
                                                        Name is required!
                                                    </div>
                                                    <div [hidden]="!titlename.errors.minlength">
                                                        Name must be at least 3 characters long.
                                                    </div>
                                                    <div [hidden]="!titlename.errors.maxlength">
                                                        Name cannot be more than 30 characters long.
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <input type="email" class="form-control" id="signup_email" placeholder="Email" [(ngModel)]=" signup_email" name="signup_email" #regmail="ngModel"  pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$" required>
                                                <div *ngIf="regmail.errors && (regmail.dirty || regmail.touched) " class="alert alert-danger">
                                                    <div [hidden]="!regmail.errors.required">
                                                        Email is required!
                                                    </div>
                                                    <div  *ngIf="regmail.errors && regmail.errors.pattern">
                                                        Invalid Email!
                                                    </div>
                                                </div>
                                            </div>
                                            <input class="btn btn-lg btn-success btn-block" [class.disabled]="!customerregisterForm.form.valid" type="submit" value="Create Account">
                                        </fieldset>
                                    </form>
                                    <hr/>
                                    <ngb-alert *ngIf="logError" type="danger" (close)="closeAlert(alert)" class="ichat-admin-log-error" [dismissible]="false">{{errorMessage}}</ngb-alert>

                                    <!--
                                     <div class="text-center ">
                                        <h4>OR</h4>
                                    </div>
                                    <input class="btn btn-lg btn-facebook btn-block"  value="Sign up via facebook">
                                    -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

1 个答案:

答案 0 :(得分:0)

在您的组件中,添加以下内容:

 var str = 'test//123_456';
 var new_str = str .replace(/\//g, '').replace(/_/g, '');
 console.log(new_str);

您只需要重置表单