Rif*_*fal 6 angular2-directives angular2-template ng-bootstrap
我怎样才能得到 angular 2 中的元素?如果我在 html 中有这个
<ng-template #content let-c="close" let-d="dismiss">
<div class="modal-header">Header</div>
<div class="modal-body">Body</div>
<div class="modal-footer">footer</div>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
如果我使用按钮打开内容,我将它用于 ngBmodal ng-bootstrap 其工作 = 按钮
(click)="open(content,data.id)"
Run Code Online (Sandbox Code Playgroud)
然后我想在这种情况下从组件打开内容,我从其他页面重定向并打开内容
ngOnInit() {
this.activatedRoute.queryParams.subscribe((params: Params) => {
let id = params['id'];
if(id != undefined){
this.open('content',id);
}
});
}
open(content, id) {
this.dataModal = {};
this.getDataModal(id);
this.mr = this.modalService.open(content, { size: 'lg' });
}
Run Code Online (Sandbox Code Playgroud)
模式打开但不使用 html,我尝试 afterviewinit 来获取 #content 它不起作用谢谢,对不起我的英语:v
首先导入 NgbModal 和 ModalDismissReasons
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
并将 modalservice 添加到构造函数
private modalService: NgbModal
看:
https://ng-bootstrap.github.io/#/components/modal/examples#options
然后在你的打字稿文件中:
1 - 导入 TemplateRef 和 ViewChild,例如:
import { TemplateRef, ViewChild } from '@angular/core';
Run Code Online (Sandbox Code Playgroud)
2 - 创建绑定 ngtemplate 的变量(在构造函数之前添加):
@ViewChild('content')
private content: TemplateRef<any>;
Run Code Online (Sandbox Code Playgroud)
3 - 从打字稿打开模态:
this.modalService.open(this.content);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6761 次 |
| 最近记录: |