Angular 6.x在IE 11中无法正常工作-错误:参数无效 [英] Angular 6.x not working in IE 11 - Error: Invalid argument

查看:125
本文介绍了Angular 6.x在IE 11中无法正常工作-错误:参数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Angular 6.x应用,可以在Chrome中完美运行.问题是尝试在IE 11中运行它时出现错误:

错误:参数无效.在DefaultDomRenderer2.prototype.setProperty ...

已经尝试了StackOverflow中所有我无法找到的答案.我在这里列出主题,因此你们不会尝试使用它们作为答案:

  • 添加了IE所需的所有polyfill,但仍然存在相同的问题.
  • 添加到头部标签:

    <meta http-equiv="X-UA-Compatible" content="IE=11">
    

感谢您的帮助.

解决方案

我已找到问题并解决.我写这个答案是为了节省其他人面对这个问题的时间.

问题是将一个不正确值的变量绑定到 HTML属性(任何HTML属性).

例如

为变量分配 dir 属性 p 标签,必须,必须使用 dir 属性的可能值之一进行定义,这些值是:ltr | rtl | auto

在html中有此行:<p [dir]="myDir">Test</p>

myDir = undefinedmyDir = 'bla bla bla'或任何其他不正确的值时-我们会收到错误消息.

myDir = 'rtl'或任何其他正确值时-我们不会出现错误.

添加了 DEMO 以在IE中运行,以查看此错误的再现.

结论我想我们可以说,绑定到HTML属性时,我们必须非常小心以拥有有效的属性值,这样我们就不会遇到这个问题. /p>

I have an Angular 6.x app running perfectly in Chrome. The problem is when trying to run it in IE 11, I'm getting the error:

Error: Invalid argument. at DefaultDomRenderer2.prototype.setProperty...

Already tried all answers in StackOverflow that I could find with no help. I'm listing theme here so you guys won't try them as answers:

  • Added all polyfills needed for IE but still having the same problem.
  • Added in head tag:

    <meta http-equiv="X-UA-Compatible" content="IE=11">
    

Thank you for helping.

解决方案

I've found the problem and fixed it. I'm writing this answer to save time for others facing this problem.

The problem is binding an incorrect valued variable to an HTML attribute (any HTML attribute).

e.g.

Assigning a variable to a dir attribute in a p tag, must be defined with one of the possible values for dir attribute, which are: ltr | rtl | auto

Having this line in html: <p [dir]="myDir">Test</p>

When myDir = undefined or myDir = 'bla bla bla' or any other incorrect value - we'll get an error.

When myDir = 'rtl' or any other correct value - we won't get an error.

Added a DEMO to run in IE for seeing this error reproduced.

For conclusion I think we can say that when binding to an HTML attribute we'll have to be very careful to have a valid attribute's value, this way we won't face this problem.

这篇关于Angular 6.x在IE 11中无法正常工作-错误:参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆