use*_*630 6 typescript angular
我有一个按钮,点击它我打开一个bootstrap模态弹出窗口.模态弹出窗口包含一些带有提交按钮的字段.我想在保存数据时关闭弹出窗口.我无法使用数据解除,因为它会在用户点击按钮后立即关闭弹出窗口.有没有办法通过打字稿关闭弹出窗口?
expense.component.html
<div id="AddExpense" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Expense</h4>
</div>
<div class="modal-body">
<form id="form" (ngSubmit)="saveExpense();">
<div class="form-group">
<table class="table table-responsive" style="border:0">
<tr *ngFor="#column of columnInputs" style="height:20px;">
<td class="text-right" style="padding-top:10px;border:0">
<h4> {{column.name | case}}: </h4>
</td>
<td class="text-center" style="padding-top:10px;border:0">
<input *ngIf="column.name != 'status'" type="{{column.name == 'created_Date' ? 'date' : 'text'}}" name="{{columns.name}}" required [(ngModel)]="column.value" class="form-control" />
<select class="form-control" *ngIf="column.name == 'status'" [(ngModel)]="column.value" name="{{column.name}}" required>
<option value="status">--Select--</option>
<option value="1">Paid</option>
<option value="2">Unpaid</option>
</select>
</td>
</tr>
</table>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg"> Add Expense </button>
</div>
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
小智 8
你可以使用关闭按钮上的操作
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" #closeAddExpenseModal>×</button>
<h4 class="modal-title">Add Expense</h4>
</div>
Run Code Online (Sandbox Code Playgroud)
并且在您的控制器中,您可以在使用的操作后添加此行
this.closeAddExpenseModal.nativeElement.click();
Run Code Online (Sandbox Code Playgroud)
您需要将此导入添加到控制器
import { ViewChild, ElementRef} from '@angular/core';
Run Code Online (Sandbox Code Playgroud)
您还需要定义closeAddExpenseModal
@ViewChild('closeAddExpenseModal') closeAddExpenseModal: ElementRef;
Run Code Online (Sandbox Code Playgroud)
Mar*_*ano -3
我不确定你真正需要做什么,但如果你想用打字稿关闭模态,你可以给你的 html 模态提供一个 id 并调用“隐藏”方法。
$('#newPostModal').modal('hide');
Run Code Online (Sandbox Code Playgroud)
抱歉,如果这不是您想要的,也许您能更好地解释我,我可以帮助您
| 归档时间: |
|
| 查看次数: |
14800 次 |
| 最近记录: |