Directive rendered via UI-Grid cellTemplate rendering incorrectly

烂漫一生 提交于 2019-12-10 15:22:15

问题


I am experiencing a strange issue in that my directive seems to be executing on stale row.entities, meaning it does not get the new values as you scroll down or modify the sort of the grid. The initial ~20 rows render fine but past that the directives become disassociated with the rows.

See my very hacked together example here.


回答1:


It looks like during sort values of the expression you pass to directive change, but the expression itself stays the same.

You should change scope & expression binding to = value binding (and access the value with scope.installs, without function call), then you will be able to track the changes.

// ...
scope: {
  installs: '='
},
// ...

Then, to track the changes you can use scope.$watch and put your code inside.

link: function (scope, element, attrs) {
  scope.$watch('installs', function(newValue) {
    // your code, you can use newValue as current installs value
    var installs = newValue;
    // ...
  });
}

Example here.



来源:https://stackoverflow.com/questions/34321797/directive-rendered-via-ui-grid-celltemplate-rendering-incorrectly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!