Search code examples
javascriptangularjshtml-selectangular-filters

  in script is not getting compiled


I have created an application in AngularJS with a drop down with space in option using a filter. The application is working fine but the   which I have put for space is not getting compiled.

My code is as given below

JSFiddle

html

<select>
    <option ng-repeat="(key, value) in headers">{{value | space}}
    </option>
</select>

script

app.filter('space', function() {
  return function(text) {
       if(_.isUndefined(text.mainId))
       {
           console.log('entered mainId');
           return text.value;
       }
       else
       {
           console.log('entered');
           return '&nbsp;&nbsp;&nbsp;'+text.value;
       }
  };

Solution

  • It works by giving the unicode value for &nbsp;.

    app.filter('space', function() {
      return function(text) {
           if(_.isUndefined(text.mainId))
           {
               console.log('entered mainId');
               return text.value;
           }
           else
           {
               console.log('entered');
               return '\u00A0\u00A0\u00A0'+text.value;
           }
      };
    

    Answer from here