I am not able to get the two way binding in angular4 working. Here is the component code.
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-date-selector',
templateUrl: './date-selector.component.html',
styleUrls: ['./date-selector.component.css']
})
export class DateSelectorComponent implements OnInit {
private statDate: Date;
constructor() { }
ngOnInit() {
this.statDate = new Date()
}
goToPreviousDay(): void
{
console.log("previous day clicked");
this.statDate.setDate(this.statDate.getDate() - 1);
console.log(this.statDate);
}
goToNextDay(): void
{
console.log("next day clicked");
this.statDate.setDate(this.statDate.getDate() + 1);
console.log(this.statDate);
}
}
I am referring to statDate in my partial like this.
<div>
<a><span class="glyphicon glyphicon-chevron-left" (click)=goToPreviousDay()></span></a>
<span class="text-center text-muted" [(innerText)]="statDate"></span>
<a><span class="glyphicon glyphicon-chevron-right" (click)=goToNextDay()></span></a>
</div>
Console log shows that the statDate is getting updated, but the same is not getting reflected in the UI.