问题
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 ' '+text.value;
}
};
回答1:
It works by giving the unicode value for
.
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