Sno*_*lax 1 javascript twitter-bootstrap typescript ng-bootstrap angular
通常,打开模态框时,通过 HTML 调用该函数:
<button class="btn btn-lg btn-outline-primary" (click)="open(content)">Launch demo modal</button>
Run Code Online (Sandbox Code Playgroud)
这将打开模式:
<ng-template #content let-modal>
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Profile update</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="dateOfBirth">Date of birth</label>
<div class="input-group">
<input id="dateOfBirth" class="form-control" placeholder="yyyy-mm-dd" name="dp" ngbDatepicker #dp="ngbDatepicker">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="dp.toggle()" type="button"></button>
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="modal.close('Save click')">Save</button>
</div>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
但是,由于情况(我正在使用 Google Charts 并且我可以使用的 HTML(click) = "open(content"没有暴露给我),我需要能够通过 javascript/typescript 打开模式。
我尝试这样做:
open(content) {
this.modalService.open(content, {ariaLabelledBy: 'modal-basic-title'}).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
select(event: ChartSelectEvent) {
this.open(content); //<--Attempt to Open Modal
if ('deselect' === event.message) {
}
else if ('select' === event.message) {
}
}
Run Code Online (Sandbox Code Playgroud)
我的尝试没有打开模式。所以,我认为我需要做的是如何template reference variable (#content)通过打字稿调用,但我不确定如何
您可以通过以下方式获取对模板的引用@ViewChild("content"):
@ViewChild("content") private contentRef: TemplateRef<Object>;
Run Code Online (Sandbox Code Playgroud)
并使用该变量打开模式:
this.open(this.contentRef);
Run Code Online (Sandbox Code Playgroud)
请参阅此 stackblitz的演示。
| 归档时间: |
|
| 查看次数: |
3412 次 |
| 最近记录: |