Search code examples
javascriptangulartypescriptopenseadragon

How to import javascript file into angular4 project and use it's function inside component?


I am trying to import openseadragon.min.js file in index.html and using it's function like below,

var viewer = OpenSeadragon({
  id: "seadragon-viewer"
});

But it is throwing error like OpenSeadragon is undefined.

Any solutions will be appreciated, Thank you


Solution

  • Try declaring the variable at the top of your component immediately below your imports, not inside your class export statement.

    import { Component } from '@angular/core';
    
    declare var OpenSeadragon: any;
    
    @Component({
    ...
    })