加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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它不起作用
谢谢,对不起我的英文: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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读