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:

<div ng-if="str.includes('test')" class="someClass"><span>Some text</span></div>

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

str.includes(searchString[, position])

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:

<div ng-if="str.indexOf('test') >= 0" class="someClass"><span>Some text</span></div>

as per the syntax below:

str.indexOf(searchValue[, fromIndex])

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

Advertisements

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

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: