IE11 and String.prototype.includes() in Angular directives

Just come across an interesting behaviour with Angular directives and E11. Apparently E11 does not seem to work with the function String.prototype.includes(), for example:

[code language=”html”]
<div ng-if="str.includes(‘test’)" class="someClass"><span>Some text</span></div>
[/code]

where str == ‘Sometest‘ and the generic syntax is as below:

Browser’s compatibility is an issue with IE11 and generally speaking it is poor across IE, so it is highly recommended to use this, instead:

[code language=”html”]
<div ng-if="str.indexOf(‘test’) >= 0" class="someClass"><span>Some text</span></div>
[/code]

as per the syntax below:

IndexOf method returns the index of the string as passed in.  If the value is not found, it returns -1.

Further documentation:

MDN documentation for includes

MDN documentation for indexOf

Posted on December 23, 2017, in Uncategorized. Bookmark the permalink. Leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: