0

We use Angular 4 in one of our projects, and we are using a using a internal js library for encrypting the password. We include the encryption js file in our index.html, and all the functions are on window object. So when I am trying to invoke the encrypt function , encryptBCCBase64 ,from my component like window.encryptBCCBase64(password) I am getting an error like -

Property 'encryptBCCBase64' does not exist on type 'Window'.

So how do I call this method from my component?

user2746912
  • 51
  • 1
  • 1
  • 4
  • Does this answer your question? [angular4 how to call a function in a external js](https://stackoverflow.com/questions/44623348/angular4-how-to-call-a-function-in-a-external-js) – maio290 Mar 14 '20 at 03:36
  • @maio290 thanks of the answer, but this would mean that I will have to make a copy of the file into my project folder, and not have a latest version of the file, so how do I this dynamically ? Say when I the refer the the script from my html, I'd be giving it as – user2746912 Mar 14 '20 at 03:53
  • 1
    Try adding `declare let window: any;` at the top of the file where you use your method – David Mar 14 '20 at 09:30

1 Answers1

0

You are using a custom Window, that extends the original Window object. You should declare an interface with the added properties, something like

export interface CustomWindow extends Window {
  encryptBCCBase64: (string) => void;
}
export class YourClass {
  private window: CustomWindow;
  constructor(@Inject(DOCUMENT) private document: Document) {
    this.window = this.document.defaultView as any;
  }
  ngOnInit() {
    // usage example
    console.log(this.window.encryptBCCBase64);
  }
}

Similar to what is explained in this response.

Not sure if it works for angular 4.