in script is not getting compiled

前提是你 提交于 2019-12-25 16:22:52

问题


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;
       }
  };

回答1:


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




回答2:


Try like this return '\u00A0' + text.value;

Javascript doesn't know that you want to parse html entity, that's why we must use unicode code.

working fiddle



来源:https://stackoverflow.com/questions/28804718/nbsp-in-script-is-not-getting-compiled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!