I've created a simple service texts-data.service.ts
selectedTextNumber:number = 1;
constructor() {
setInterval(()=>{
this.selectedTextNumber = 0;
console.log("chans: "+this.selectedTextNumber);
},2000);
}
getCurrentTextNumber(){
return this.selectedTextNumber;
}
I use it in other components: other.component.ts
import { TextsDataService } from "../../services/texts-data.service";
export class OtherComponent implements OnInit {
fontName:string;
constructor(public textsDataService: TextsDataService) {
this.selectedTextNumber = textsDataService.getCurrentTextNumber();
let currentFont = textsDataService.allTexts[this.selectedTextNumber];
this.fontName = currentFont.fontName;
}
I am interested in updating the view, once the services data changes. In my case, it changes after 2 seconds, but the view never gets updated. How do I make it refresh itself?
HTML:
<input type="text" class="form-control" aria-label="Text input with dropdown button" value="{{fontName}}">