table如果值为空,我需要在单元格中显示不间断的空格.这是我的模板:
<td class="licnum">{{participant.LicenseNumber}}</td>
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它不起作用:
<td class="licnum">{{participant.LicenseNumber} || "$nbsp;"}</td>
Run Code Online (Sandbox Code Playgroud)
这是它返回null值的问题:

如果许可证号码带有null值,则单元格为空,行着色如下所示.
使用lucuma的建议,它显示了这个:

更改过滤器中的if语句后,仍然不显示非null值:

luc*_*uma 15
你有什么应该工作.您缺少一个结束,}并且在表达式的中间有一个需要删除.
这是一个演示,显示您的解决方案正在运行和ng-if. http://plnkr.co/edit/UR7cLbi6GeqVYZOauAHZ?p=info
过滤器可能是要走的路线,但是您可以使用简单的ng-if或ng-show(在td或甚至是跨度上)来实现:
<td class="licnum" ng-if="participant.LicenseNumber">{{participant.LicenseNumber}}</td>
<td class="licnum" ng-if="!participant.LicenseNumber"> </td>
Run Code Online (Sandbox Code Playgroud)
要么
<td class="licnum"><span ng-if="participant.LicenseNumber">{{participant.LicenseNumber}}</span><span ng-if="!participant.LicenseNumber"> </span></td>
Run Code Online (Sandbox Code Playgroud)
我提供这个作为替代解决方案,不需要向控制器/过滤器添加代码.
您可以阅读一些关于此方法的内容:ifular语句在AngularJS模板中
angular.module('myApp',[])
.filter('chkEmpty',function(){
return function(input){
if(angular.isString(input) && !(angular.equals(input,null) || angular.equals(input,'')))
return input;
else
return ' ';
};
});
Run Code Online (Sandbox Code Playgroud)
正如@Donal所说,为了使这个工作,你需要使用这样的ngSanitize's指令ng-bind-html:
<td class="licnum" ng-bind-html="participant.LicenseNumber | chkEmpty"></td>
Run Code Online (Sandbox Code Playgroud)
编辑:
这是一个简单的例子:http://jsfiddle.net/mikeeconroy/TpPpB/