Q . Ignore Typescript Errors “property does not exist on value of type” in angular4

Brad Johnson. asked, Apr 09 ' 2018

Below is the my code in angular 4 to load dynamic script.

<script>    
    var script = document.createElement("script")
    script.type = "text/javascript";

    if (script.readyState){  //IE
        script.onreadystatechange = function(){
            if (script.readyState == "loaded" ||
                    script.readyState == "complete"){
                script.onreadystatechange = null;
                callback();
            }
        };
    } else {  //Others
        script.onload = function(){
            callback();
        };
    }

    script.src = url;
    document.getElementsByTagName("head")[0].appendChild(script);
</script>

Error : [ts] Property 'readyState' does not exist on type 'HTMLScriptElement'.

Why the above error is coming in angular4?

  • angularJS
  • error
  • load-external-script
  • angular4

1 Answers

I've found it searching for same TypeScriptException...

Just use any keyword like

var script: any = document.createElement("script")

 

Leave a Ansewer