AngularJS bug in IE with style vs ng-style

孤者浪人 提交于 2019-12-19 08:22:48

问题


I'm using Angular JS v1.1.5, and found an interesting IE-related issue.

In IE 9, 10, 11 and Edge, the following does not seem to work, even though it works fine in Chrome:

<div style="width: {{progress.percent()}}%;"></div>

Whereas this works in all browsers:

<div ng-style="{width: progress.percent() + '%'}"></div>

I'm curious why the first option doesn't work in IE/Edge. Are there any known bugs around this?


回答1:


When IE 9 & 10 tries to render that HTML, it basically removes the invalid HTML found on HTML to be parse.

So having style="display: {{'block'}}" consider as invalid html, because it has unknown {{}} syntax & it make that attribute rendered as style=""


Other than having ng-style there you could use ng-attr-* directive like below

<div ng-attr-style="{{'width: '+ progress.percent() +'%;'}}"></div>

which will create style attribute when progress.percent() value does changed.

For more information look at this old logged github issue

How style attribute become ""?



来源:https://stackoverflow.com/questions/36072798/angularjs-bug-in-ie-with-style-vs-ng-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!