Developer GuideDeveloper Guide // ieie
This document describes the Internet Explorer (IE) idiosyncrasies when dealing with custom HTML attributes and tags.Read this document if you are planning on deploying your Angular application on IE v8.0 or earlier.
To make your Angular application work on IE please make sure that:
You polyfill JSON.stringify if necessary (IE7 will need this). You can use JSON2 or JSON3 polyfills for this.1.
you do not use custom element tags such as (use the attribute version instead), or2.if you do use custom element tags, then you must take these steps to make IE happy:3.
1. 2. 14. 15. 16. ... ...17. 18.19.
The important parts are:
xmlns:ng - namespace - you need one namespace for each custom tag you are planning on using.document.createElement(yourTagName) - creation of custom tag names - Since this is an issue only for olderversion of IE you need to load it conditionally. For each tag which does not have namespace and which is not defined inHTML you need to pre-declare it to make IE happy.
IE has issues with element tag names which are not standard HTML tag names. These fall into two categories, and eachcategory has its own fix.
If the tag name starts with my: prefix than it is considered an XML namespace and must have correspondingnamespace declaration on If the tag has no : but it is not a standard HTML tag, then it must be pre-created using
document.createElement('my-tag')If you are planning on styling the custom tag with CSS selectors, then it must be pre-created usingdocument.createElement('my-tag') regardless of XML namespace.
The Good NewsThe good news is that these restrictions only apply to element tag names, and not to element attribute names. So thisrequires no special handling in IE: .
What happens if I fail to do this?Suppose you have HTML with unknown tag mytag (this could also be my:tag or my-tag with same result):
1. 2. some textsome text3. 4.5.
It should parse into the following DOM:
#document#document1. +-+- HTML HTML2. +-+- BODY BODY3. +-+- mytag mytag4. +-+- #text: some text#text: some text5.
The expected behavior is that the BODY element has a child element mytag, which in turn has the text some text.But this is not what IE does (if the above fixes are not included):
#document#document1. +-+- HTML HTML2. +-+- BODY BODY3. +-+- mytag mytag4. +-+- #text: some text#text: some text5. +-+- //mytagmytag6.
In IE, the behavior is that the BODY element has three children:A self closing mytag. Example of self closing tag is
. The trailing / is optional, but the
tag is not allowedto have any children, and browsers consider
some text as three siblings not a
with some text aschild.
A text node with some text. This should have been a child of mytag above, not a sibling.2.A corrupt self closing /mytag. This is corrupt since element names are not allowed to have the / character.Furthermore this closing element should not be part of the DOM since it is only used to delineate the structure of theDOM.
CSS Styling of Custom Tag NamesTo make CSS selectors work with custom elements, the custom element name must be pre-created withdocument.createElement('my-tag') regardless of XML namespace.