我怎么能得到角2的元素?
如果我有这个在 HTML中
如果我有这个在 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>
我用它来ngBmodal ng-bootstrap
如果我使用按钮打开内容它的工作=按钮
(click)="open(content,data.id)"
然后我想从组件打开内容
在这种情况下,我从其他页面和打开的内容重定向
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' }); }
模态打开,但没有与HTML,我尝试afterviewinit得到#content它不起作用
谢谢,对不起我的英文:v
解决方法
首先导入NgbModal和ModalDismissReadons并将modalservice添加到构造函数,请参阅:
https://ng-bootstrap.github.io/#/components/modal/examples#options
然后在你的打字稿文件中:
1 – 导入TemplateRef和ViewChild,例如:
import { TemplateRef,ViewChild } from '@angular/core';
2 – 创建绑定ngtemplate的变量(在构造函数之前添加):
@ViewChild('content') private content: TemplateRef<any>;
3 – 打字稿中的打开模态:
this.modalService.open(this.content);