问题
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