javascript - 单元格模板中的 Angularjs 指令 ng-hide 不绑定(bind)网格数据的更改

标签 javascript angularjs

单元格模板中的 Angular 指令 ng-hide 不与网格数据更改的最新数据绑定(bind)。请查看 plunkr 了解更多详细信息:- http://plnkr.co/edit/rj0PrfyzeyVeV8Q8RWtG?p=preview 在 plunker 模板中,字段不会随着数据的变化而更新。

var app = angular.module('app', ['ngTouch', 'ui.grid']);

app.controller('MainCtrl', function ($scope, $timeout) {
  $scope.gridOpts = {        
        columnDefs: [
          { name:'name', field: 'name' },
          { name:'isActive', field: 'isActive'},
          { name:'template',cellTemplate:'<div><a ng-hide={{row.entity.isActive=="Y"}}>Active</a><a ng-hide={{row.entity.isActive=="N"}}>Deactive</a></div>'}
        ]
  };

  $scope.waiting = "Waiting...";
  $timeout(function () {
    $scope.gridOpts.data = [{ name: 'Bob' ,isActive:'Y'}];
  }, 3000)
  .then(function() {
    $timeout( function() {
      $scope.gridOpts.data = [{ name: 'John',isActive:'N' }];
    }, 3000);
    $scope.waiting = "Waiting again...";
  })
});

最佳答案

您需要在 ng-hide 中添加一个表达式

The ngHide directive shows or hides the given HTML element based on the expression provided to the ngHide attribute.

所以你的ng-hide 应该像

..ng-hide=row.entity.isActive=="Y"..

不像这种插值,

.. ng-hide={{row.entity.isActive=="Y"}}..

这里是更新的DEMO

关于javascript - 单元格模板中的 Angularjs 指令 ng-hide 不绑定(bind)网格数据的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30967010/

相关文章:

javascript - Bootstrap 容器未正确对齐

javascript - 选择警告框选项时跳转页面

javascript - 为什么我对大数字返回 undefined 而对小数字则不返回? (斐波那契数列和)

javascript - Angular JS 和 Bootstrap Accordion 不工作

javascript - VueJS : Bind div content to iframe src

javascript - jQuery 延迟 promise

javascript - Angularjs 自定义过滤器和依赖注入(inject)

javascript - Angularjs 隐藏输入字段内的文本

javascript - 如果在 Angular ng-hide 中未选择任何选项,则隐藏部分

javascript - 从 Angular 范围的 php 文件中获取 json 数据