只要字段值不是空字符串,我就需要在ui网格中显示一个按钮。我试过使用ng-if,但它不起作用。下面是我的网格选项中的代码:
{ field: 'ReleaseStatus',
width: 125,
displayName: 'Release Status',
cellTemplate:
'<div ng-if="row.entity.ReleaseStatus != """>
<button id="editBtn"
type="button"
class="btn btn-default"
data-toggle="modal"
data-target="#myModal"
ng-click="grid.appScope.launch(row)">
{{COL_FIELD}}
</button>
</div>'
},没有ng-if,按钮显示和工作很棒。但是,由于某些记录的字段ReleaseStatus为空字符串,因此不应出现该按钮。
任何援助都是非常感谢的。
发布于 2016-05-19 18:33:12
你应该这样写:
'<div ng-if="row.entity.ReleaseStatus !== \'\'">'你也可以把ng-如果直接放在你想要隐藏的屁股上。
但是,要小心使用ng-if,因为它每次都会创建一个新的范围。
发布于 2021-12-22 10:55:17
解决方案1:有一个简单的方法来完成这个任务,请看下面的示例。
{
name: 'nameishere', displayName: 'Display Name', cellTemplate:
'<div class="ui-grid-cell-contents" ng-if="grid.appScope.haveFile(row.entity.nameishere)"><a href="' + apiURL + '/InvalidFiles/{{row.entity.nameishere}}" download="{{row.entity.nameishere}}" >{{ row.entity.nameishere}}</a></div>'+
'<div class="ui-grid-cell-contents" ng-if="grid.appScope.haveNotFile(row.entity.nameishere)">{{ row.entity.nameishere}}</div>'
},和创建多个函数或使用一个与if-else一起使用的函数
$scope.haveFile = function (data) { return data == 'No File to Display' };
$scope.haveNotFile = function (data) { return data != 'No File to Display' };解决方案2:您应该以不同的方式编写它,字符串和整数句柄。
cellTemplate:'<div ng-if="row.entity.status !== \'Your String Here\'">'
cellTemplate:'<div ng-if="row.entity.status !== 23>'解决方案3:使用ng-如果是这样
cellTemplate:'<div>{{row.entity.status == 0 ? "Active" : (row.entity.status == 1 ? "Non Active" : "Deleted")}}</div>';https://stackoverflow.com/questions/37331359
复制相似问题