You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 26, 2026. It is now read-only.
In crud-grid-directive.js, I was having a really hard time getting my lookups to work. It seems that c is getting out of scope in the loop in $scope.setLookupData. I kept getting errors because c.lookup was undefined. I tried putting everything in the loop in a closure like so:
$scope.setLookupData = function () {
for (var i = 0; i < $scope.columns.length; i++) {
(function (i) {
var c = $scope.columns[i];
if (c.lookup && !$scope.hasLookupData(c.lookup.table)) {
var res = crudGridDataFactory(c.lookup.table).query();
res.$promise
.then(function (data) {
$scope.setIndividualLookupData(c.lookup.table, data); // c out of scope here?
})
.catch(function (data) {
console.log("Error: ", data);
});
}
})(i);
}
};
Now it works perfectly. There are some other changes to how the promise is used that you may ignore or include at your discretion - I ended up making them while trying to debug the problem and thought they were good enough to keep in.
In crud-grid-directive.js, I was having a really hard time getting my lookups to work. It seems that c is getting out of scope in the loop in $scope.setLookupData. I kept getting errors because c.lookup was undefined. I tried putting everything in the loop in a closure like so:
Now it works perfectly. There are some other changes to how the promise is used that you may ignore or include at your discretion - I ended up making them while trying to debug the problem and thought they were good enough to keep in.
The closure idea came from StackOverflow:
http://stackoverflow.com/questions/17244614/promise-in-a-loop
Hope this is useful.
-k