in脚本未被编译

  in script is not getting compiled

本文关键字:脚本 编译 in amp nbsp      更新时间:2023-09-26

我在AngularJS中创建了一个应用程序,其中有一个下拉菜单,选项中有空格,使用了一个过滤器。应用程序运行良好,但我为空间放置的 没有得到编译。

我的代码如下所示

JSFiddle

html

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

脚本

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

它通过为&nbsp;提供unicode值来工作。

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

从这里回答

像这样尝试return ''u00A0' + text.value;

Javascript不知道您想要解析html实体,这就是为什么我们必须使用unicode代码。

工作小提琴