incuna / angular-bind-html-compile

Directive that calls $compile on trusted HTML, allowing directives in an API response.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Odd comment doesn't match code logic

david-mark opened this issue · comments

If this is a case that only happens some of the time, then why does the code always call the - toString - method? And if - value - is "falsey" (e.g. an empty string, 0, null, etc.) then it will be passed to the - html - method (which sets the innerHTML property of the element)?

The intent of the code is just not clear. For example, what is allowed for the - value - argument? For another, what is supposed to happen if it is a disallowed value (e.g. assume that setting the innerHTML property to "null" is not intended). The comment isn't helping either; if anything, it makes the intent less clear.

// In case value is a TrustedValueHolderType, sometimes it
// needs to be explicitly called into a string in order to
// get the HTML string.

element.html(value && value.toString());