6

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>

(Or)

<ng-container *ngTemplateOutlet="mytemplate" ></ng-container>
Pete
  • 769
  • 7
  • 20
Mahi Tej Gvp
  • 984
  • 1
  • 14
  • 34

2 Answers2

3

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>

Assign it:

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

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

ngAfterViewInit() {
  this.myEl.changes.subscribe(_ => console.log(_));
}
Julius Dzidzevičius
  • 10,775
  • 11
  • 36
  • 81
-1

You can use

public mycondition: boolean = true;   ///according to need make it true or false

<ng-template *ngIf="mycondition"> ... </ng-template>
Lavkush Gupta
  • 103
  • 13