admin管理员组

文章数量:1336631

I have this code below. Which is a straight forward way of using NgOptions to plot some options in a form.

function NameCtrl($scope) {
  $scope.theOptions = [{
    'label': 'The Opt<sup>&trade;</sup>',
    'id': 3
  }]

}
<html ng-app>

<head>
  <meta charset="utf-8">
  <title>Angular.js Example</title>
  <script src="//cdnjs.cloudflare/ajax/libs/angular.js/1.2.1/angular.min.js"></script>

</head>

<body ng-controller="NameCtrl">
  <select ng-model="selectedOption" ng-options="x.id as x.label for x in theOptions">
        <option value="">Select</option>
      </select>
</body>

</html>

I have this code below. Which is a straight forward way of using NgOptions to plot some options in a form.

function NameCtrl($scope) {
  $scope.theOptions = [{
    'label': 'The Opt<sup>&trade;</sup>',
    'id': 3
  }]

}
<html ng-app>

<head>
  <meta charset="utf-8">
  <title>Angular.js Example</title>
  <script src="//cdnjs.cloudflare./ajax/libs/angular.js/1.2.1/angular.min.js"></script>

</head>

<body ng-controller="NameCtrl">
  <select ng-model="selectedOption" ng-options="x.id as x.label for x in theOptions">
        <option value="">Select</option>
      </select>
</body>

</html>

My question is: Is there any way I can make the Option The Opt<sup>&trade;</sup> to render The Opt in a Select Dropdown? As I cannot use ng-bind-html. Is there any way I can achieve this? Any help is appreciated.

Share edited Mar 13, 2017 at 14:52 SAMUEL 8,5623 gold badges45 silver badges43 bronze badges asked Mar 13, 2017 at 13:40 RoyRoy 1,9771 gold badge15 silver badges21 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You can use ng-repeat and use ng-bind-html with that. See the code below:

<select ng-model="selectedOption">
    <option value="">Select</option>
    <option ng-repeat="x in theOptions" ng-bind-html="x.label" value="{{x.id}}" id="{{x.id}}"></option>
</select>

If you need to use ng-options, here are a few related solutions and here's a plunker showing this solution with your code. Hope this helps. Note that I also changed your tags to an html entity code.

本文标签: javascriptUsing ngbindhtml or something similar in SelectOption tagStack Overflow