I am currently incorporating the Third Party Library called MarvinJS into my Angular5 Application. In order to successfully handle a MarvinJS promise, I need to execute the method
this.sharedService.openMarvinModal(false);
.
However, upon executing this method, an error occurs.
Uncaught (in promise) TypeError: Cannot read property 'sharedService' of undefined
at eval (marvin-modal.component.ts:58)
at <anonymous>
Here is the relevant code snippet:
import {
Component,
OnInit
} from "@angular/core";
import { SharedService } from "../services/shared.service";
import * as $ from "jquery";
declare var MarvinJSUtil: any;
@Component({
selector: "app-marvin-modal",
templateUrl: "./marvin-modal.component.html",
styleUrls: ["./marvin-modal.component.scss"]
})
export class MarvinModalComponent
implements OnInit {
constructor(private sharedService: SharedService) {}
ngOnInit() {
}
getStructure() {
const p = MarvinJSUtil.getEditor("#sketch");
p.then(function(sketchInstance) {
sketchInstance.exportStructure("smiles").then(function( source) {
console.log(source);
this.sharedService.openMarvinModal(false);
});
});
}
}
I am seeking assistance on how to resolve this issue. Any help would be greatly appreciated.
Thank you in advance.