ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

$sce.trustAsHtml rejects numeric values

Open demkinmaxim opened this issue 12 years ago • 3 comments

When the data have int values to be printed into choices span, it gets error:

Error: [$sce:itype] Attempted to trust a non-string value in a content requiring a string: Context: html

// ERROR on value = 1;
// OK on value = "1"
scope.trustAsHtml = function(value) {
      return $sce.trustAsHtml(value);
};

I've used string conversion to overcome:

return $sce.trustAsHtml("" + value);

Btw, in the test I have 3 select fields with 1 element in each. I'm using only one trustAsHtml() (just span, without small) I get 21 errors on page load. Why it is so much?

demkinmaxim avatar Mar 07 '14 13:03 demkinmaxim

Another error, because number is not a string, and does not have replace method.

TypeError: Object 92 has no method 'replace'

demkinmaxim avatar Mar 07 '14 13:03 demkinmaxim

Edit: obsolete message according to ui-select v0.1.0

Obviously it only works with strings, so you will have to use toString():

<choices data="people | filter: $select.search">
  <div ng-bind-html="trustAsHtml((item.name | highlight: $select.search))"></div>
  <small ng-bind-html="trustAsHtml((item.age.toString() | highlight: $select.search))"></small>
</choices>

tkrotoff avatar Mar 22 '14 09:03 tkrotoff

I have pushed a new release and ui-select does not provide function trustAsHtml() anymore, you should use ngSanitize instead (or create your own trustAsHtml() function using $sce) More explanations inside the FAQ

tkrotoff avatar Mar 25 '14 14:03 tkrotoff