我在 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 ' '+text.value;
}
};
最佳答案
它的工作原理是给出 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;
}
};
关于javascript - 脚本中没有被编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28804718/