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>

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>

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.

%d bloggers like this: