I am using Angular2 and displaying a variable on the page. The page has a button that I click and a data service is invoked. Inside the dataservice call, I change the value of the variable and expect the change to be reflected on the page. However, I still see the old value. Only when I click on another link and then come back to this page, do I see the new value reflected. Any changes to the variable that I make outside a dataservice call is reflected immediately. Only the changes within the dataservice call is not reflected: Below is some code snippet:
HTML template:
<button type="button" class="btn (click)="clickNextButton()">
<span>save</span>
</button>
{{text}}
Typescript class
export class ConfigComponent implements OnInit {
public text = '';
..
..
private clickNextButton(): void {
this.text = 'abc;
this.dataService.getConfig()
.then((config: IConfig): void => {
console.log('printed');
this.text = 'xyz';
console.log('printed..');
});
}
}
So, I click on the button and the value changes to abc on the page but it does not change to xyz. console logs are printed fine, so I know for sure that the code is reached. Why the changes I make to the variable inside the dataservice call not getting reflected on the page? How do I fix this issue?
Update:
This issue occurs only when the component is included and used in another component, as:
<prod-setup
....
</prod-setup>
When I change variable value in the dataService call of the main component, it changes and reflects fine on the view. Only when I change a variable in the Data Service call of the included component, it doesn't reflect on the UI. Any idea?