I'm trying to send value which I'm getting from web service to another component but the problem is that I'm getting empty value in that another component while I can see that the value is present when I do console.log() in the current component.
AppComponent
ts
level: string = '';
getCustomer(id: string) {
this.isLoading = true;
this.customerService.getOne(id)
.subscribe(
(data) => {
this.level = data.level;
console.log(this.level); // Here I can see the value
},
(error) => {
this.errorMessage = error;
},
);
}
html
<div class="col-lg-8">
<app-other-component [active]="level"></app-other-component>
</div>
AppOtherComponent
ts
@Input() active: string;
ngOnInit() {
console.log(this.active); // Here I'm getting an empty string
}
I think that this line is executing <app-other-component [active]="level"></app-other-component>before the value of 'level' is even filled.
How can I resolve this? thanks.
ngOnInit()is calledOnChangesto get the updated value