Relative Content

Tag Archive for angulartypescriptserviceundefined

Cannot read property of undefined (reading property )

api.service.ts //imports… @Injectable({ providedIn: ‘root’, }) export class ApiService{ public images = environment.imgUrl ;} constructor(public http: HttpClient) {} … second.service.ts imports… export class second.service.ts implements OnInit { public _api: apiService; ngOnInit(): void { this._api = this.injector.get(ApiService); } getImgUrl(){ return this._api?.images; // images property cannot be accesssed but it is defined and can be accessed in […]

Cannot read property of undefined (reading property )

api.service.ts //imports… @Injectable({ providedIn: ‘root’, }) export class ApiService{ public images = environment.imgUrl ;} constructor(public http: HttpClient) {} … second.service.ts imports… export class second.service.ts implements OnInit { public _api: apiService; ngOnInit(): void { this._api = this.injector.get(ApiService); } getImgUrl(){ return this._api?.images; // images property cannot be accesssed but it is defined and can be accessed in […]