angular2-template – 从组件角度2获取ng-template
发布时间:2020-12-17 17:00:06 所属栏目:安全 来源:网络整理
导读:我怎么能得到角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 我用它来ngBmodal ng-bootstrap
我怎么能得到角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> 我用它来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它不起作用 解决方法
首先导入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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |