I have the following in my Angular component:
class Test implements ....{
duration:{from:number, to:number}
constructor(){
this.duration.from = "ddd";//set after some calculations
this.duration.to = "ddd";
}
}
The above returns an error of "cannot set property from of undefined".
Where am I going wrong?
durationwas of type{from:number, to:number}. That does not initialize it.this.durationisundefinedat the time the constructor runs. Usethis.duration = {from: 'ddd', to: 'ddd'}to initialize it.duration = {...}