Angular 以编程方式打开ng引导模式

Angular 以编程方式打开ng引导模式,angular,typescript,modal-dialog,ng-bootstrap,ng-template,Angular,Typescript,Modal Dialog,Ng Bootstrap,Ng Template,我有一个角度4页,包括ng引导模式。我的代码看起来像这样 foo.html [...] <button class="btn btn-sm btn-secondary material-icons" (click)="open(content)">search</button> <ng-template #content let-c="close" let-d="dismiss"> content in here </ng-template&g

我有一个角度4页,包括ng引导模式。我的代码看起来像这样

foo.html

[...]
<button class="btn btn-sm btn-secondary material-icons"
(click)="open(content)">search</button>

<ng-template #content let-c="close" let-d="dismiss">
    content in here
</ng-template>
[...]
现在,当我单击按钮时,模态打开。我现在想做的是打开ngChanges上的模型

ngOnChanges(changes: any) {
   open(content)
}

我的问题是:如何在这里获取“内容”?有没有办法通过编程方式获取ng模板?提前谢谢

要访问类中的
内容
元素,请声明:

@ViewChild('content', { static: false }) private content;
                         ^for Angular8+
并在类的顶部添加相应的导入:

import { ViewChild } from '@angular/core';
最后,在更改检测时为该元素调用open方法:

ngOnChanges(changes: any) {
   this.open(this.content);
}

从Angular 8中,还应在ViewChild中传递静态选项:
{static:false}

import { ViewChild } from '@angular/core';

@ViewChild('content', { static: false }) private content;

constructor(private modalService: NgbModal) { }

this.modalService.open(this.content);
import { ViewChild } from '@angular/core';

@ViewChild('content', { static: false }) private content;

constructor(private modalService: NgbModal) { }

this.modalService.open(this.content);