It depends on what callSomeMethod()
is doing, but one possibility is to add a directive to the *ngIf
element, and execute that logic in the OnInit
hook of that directive.
<div *ngIf="obj.someProperty" some-method-directive>
<!--render inner parts-->
</div>
And elsewhere:
@Directive({
selector='[some-method-directive]',
})
class SomeMethodDirective implements OnInit { // OnInit imported from angular2/core
ngOnInit(){
// insert your someMethod lofic
}
}
If you need access to the parent component in this method, you can get ahold of it via constructor injection in the directive:
constructor(@Host(ParentComponent) private parent: ParentComponent){ }
and you'll then have access to it via this.parent
.
This is the most analogous approach I can think of to the ng1 approach, but like I said - depending on what someMethod()
needs to accomplish, it might not be a feasible solution. If not, please comment/edit your question to explain why, and that'll give me a better idea of what we're doing here.