I am facing an issue with displaying the asynchronously initialized variable. I tried adding a ?
in the template to handle the potential undefined error, but it is giving me an unexpected expression end error.
@Component({
template: `<div>{{value?}}</div>`
})
export class CustomComponent implements OnInit {
value: number;
constructor(private _service: Service) { }
getValue() {
this._service.getValue().subscribe(data => this.value = data);
}
ngOnInit() {
this.getValue();
}
}