It depends on what callSomeMethod() does, but one of them is to add a directive to the *ngIf element and execute this logic in the OnInit tag of this directive.
<div *ngIf="obj.someProperty" some-method-directive> </div>
And in another place:
@Directive({ selector='[some-method-directive]', }) class SomeMethodDirective implements OnInit {
If you need access to the parent component in this method, you can get it through the constructor injection in the directive:
constructor(@Host(ParentComponent) private parent: ParentComponent){ }
and you will access it through this.parent .
This is the most similar approach that I can come up with for the ng1 approach, but, as I said, depending on what someMethod() needs to be done, this may not be an appropriate solution. If not, please comment / edit your question to explain why, and this will give me a better idea of ββwhat we are doing here.
source share