So, created a file with the content of the script. That too doesn't make any sense. After that I copied the content of that file and added in "ngOnInit" of the page. It worked with an error in the terminal.
example.component.ts(13,14): error TS2339: Property 'CROSSMARK' does not exist on type 'Document'.
Thanks for the help in advance.