可见ng-template时调用方法 [英] Call a method when ng-template is visible

查看:177
本文介绍了可见ng-template时调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng-template在示波器中可见或处于活动状态时是否有任何事件 是否可以通过这种方式执行任何方法来从容器中调用它?

Does ng-template have any events when it is visible or active in the scope or is it possible to execute any method in such way to call it from the container?

<ng-template (active/vissible)="callMethod()"> ... </ng-template>

(或)

<ng-container *ngTemplateOutlet="mytemplate" ></ng-container>

推荐答案

一个选项可能(对于任何DOM对象均有效)是通过ViewChildren的QueryList的

One option could be (valid for any DOM object) is via ViewChildren's QueryList's changes. You mark any DOM element (or use it's type) - <div #myEl></div>

分配:

@ViewChildren('myEl') myEl: QueryList<any>;

并订阅ngAfterViewInit中的更改(较早的AFAIK尚未创建):

And subscribe for changes in ngAfterViewInit (as earlier AFAIK its not yet created):

ngAfterViewInit() {
  this.myEl.changes.subscribe(_ => console.log(_));
}

这篇关于可见ng-template时调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆