I've been encountering some issues with my code specifically when it's called from the service.
In the app.component.html file, I have:
<div id="wrapper"></div>
Executing this code:
this.targetElement = document.getElementById('wrapper') as HTMLElement;
In app.component.ts, it works perfectly fine. However, I'm attempting to migrate it to a service, so I implemented the following:
import { Injectable } from '@angular/core';
import * as mylib from '../../assets/index.js';
@Injectable({
providedIn: 'root'
})
export class ViewerService {
window: any = window;
targetElement: HTMLElement;
viewer: any;
constructor() { }
viewerInit() {
this.targetElement = document.getElementById('wrapper') as HTMLElement;
return this.targetElement;
}
}
Subsequently, when I invoke the service from app.component.ts...
ngOnInit() {
this.viewerService.viewerInit();
}
The code doesn't seem to work from the service endpoint...
How can I rectify this situation?