Problem using a directive inside a cell template
I'm attempting to use a custom directive inside a treegrid implementation of ng-grid to show a bullet graph. The bullet graph also utilizes the ui-bootstrap popover directive. What I'm trying to accomplish is to pass dynamically generated popover information from my data model into the popover. I already modified the popover template to accept html-unsafe, so that's taken care of. However, I'm seeing weird behavior inside my directive:
.directive( 'bulletGraph', function ($timeout) {
return {
restrict: 'E',
replace: true,
scope: {
model: '=',
},
link: function(scope, element, attrs) {
$timeout(function() {
console.log(scope.model);
},1000);
},
A bit of exposition: Each grid row contains a +/- toggle which collapses/expands the tree. This only manipulates the data model bound to the ng-grid, so the grid automatically updates itself. However, there seems to be some weird timing issue. When I expand a node, the base templateURL is showing the correct info from the isolate scope 'model', but the data I'm attempting to manipulate inside the link function is returning the wrong model info - it's showing the info from the model that previously occupied that row index -- hence the $timeout, which doesn't seem to solve anything. Any idea how to get around this, or if it's a problem with ng-grid?
In short, the model defined in the isolate scope declaration is not the same model that i'm logging to the console inside the link function.
Can you show an example in a plunker so I can work through it? Thanks.
I believe I am seeing the same issue. If you use the grid's built-in search filter and type in 2, you will see that the row.entity is not in sync with the directive's output. I modified the directive somewhat to demonstrate...
.directive('bulletGraph', function ($timeout) {
return {
restrict: 'E',
replace: true,
scope: {
model: '='
},
template: '<span>{{ id }}</span>',
link: function (scope, element, attrs) {
scope.id = scope.model.id;
}}});
Using the following grid options...
$scope.gridOptions = {
showFilter: true,
data: '[{id:1},{id: 2},{id:3}]',
columnDefs: [{field: 'id', displayName: 'Id',
cellTemplate: '<span data-ng-cell-text>{{ row.entity }} <bullet-graph model="row.entity"></bullet-graph></span>'}],
};
This looks like it was solved for you in #743?