4

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
  • 741
  • 6
  • 20
Mahi Tej Gvp
  • 822
  • 1
  • 12
  • 33

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,357
  • 10
  • 33
  • 75
-1

You can use

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

<ng-template *ngIf="mycondition"> ... </ng-template>