At first, I added DomSanitizer to the component:
import { DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
Next, a class was created and included in the constructor:
export class BlocklyComponent implements OnInit {
primaryWorkspace: Blockly.WorkspaceSvg;
GEE = "PCFET0NUWVBFIGh0bWw+Cgo8aGVhZD4KPG1ldGEgY29udGVudD0idGV4dC9odG1sOyBjaGFyc...";
public geeMap: SafeResourceUrl;
constructor(private sanitizer: DomSanitizer) {}
ngOnInit() {
The NgOnInit function runs correctly, but the updateURL function (outside of NgOnInit but inside the class) throws an error stating that this.sanitizer is undefined:
//Creates de src that has to be in the iframe. What I need to do is to update this safeResourceUrl.
this.geeMap = this.sanitizer.bypassSecurityTrustResourceUrl(`data:text/html;base64,${this.GEE}`);
//Reads the events in a workspace. When it notices a change, it triggers the updateURL function
primaryWorkspace.addChangeListener(this.updateURL);
}
updateURL(primaryEvent)
{
if (primaryEvent.isUiEvent) {
return; //Do not clone ui events
};
console.log('hola');
//Problem. Here it sais that this.sanitizer is undefined.
this.geeMap = this.sanitizer.bypassSecurityTrustResourceUrl(`data:text/html;base64,${this.GEE}`);
}
This issue is familiar and I have encountered it multiple times before, however, I am currently unsure how to resolve it. I have searched various forums for a solution to the undefined problem without success. Thank you kindly