Error in IE 11 browser - EXCEPTION: Object doesn't support property or method 'matches' , other browser it works fine

后端 未结 3 1740
滥情空心
滥情空心 2020-12-29 06:53

In my case, the webpage works fine in firefox and chrome browser but in IE v.11 it shows error as error comes in IE 11 DEVELOPER TOOLS. The error shows up in developer too

相关标签:
3条回答
  • 2020-12-29 07:07

    It looks like IE implements the matches function using a non-standard name (source). That link includes a polyfill which will define the matches function so it can be used on IE.

    0 讨论(0)
  • 2020-12-29 07:24

    I was facing same issue after I updated my project from Angular 5 to 6. I found a solution with help of Derek Brown's comment. The solution is to add the following in the polyfill.ts file:

    if (!Element.prototype.matches) {
      Element.prototype.matches = Element.prototype.msMatchesSelector;
    }
    
    0 讨论(0)
  • 2020-12-29 07:30

    For those using Angular 6 and 7 (typescript) you should modify Sanjay Gupta's answer below with:

    if (!Element.prototype.matches) {
      Element.prototype.matches = (<any>Element.prototype).msMatchesSelector ||
        Element.prototype.webkitMatchesSelector;
    }
    

    The casting (well, untyping, really) allows the transpiler to parse the undefined method.

    0 讨论(0)
提交回复
热议问题