I'm using ui-grid. But I cannot get the $scope.gridApi from download function. And get the error: Cannot read property 'selection' of undefined. Somebody can tell me the reason? thanks.
$scope.gridOptions.onRegisterApi = function (gridApi) {
$log.info('gridApi...');
$scope.gridApi = gridApi;
$log.info($scope.gridApi);
};
$scope.download = function ($event) {
$event.stopPropagation();
var selectedRows = $scope.gridApi.selection.getSelectedRows();
$log.log('selectedRows....');
$log.log(selectedRows);
};
To resolve your TypeError: Cannot read properties of undefined (reading '0') , go through these steps: Ensure you are using the correct variable. Perform a simple check on your variable before using it to make sure it is not undefined. Create a default value for the variable to use if it does happen to be undefined.
The "Cannot read properties of undefined" error occurs when trying to access a property on an undefined value. You often get undefined values when: accessing a property that does not exist on an object. accessing an index that is not present in an array.
The "Cannot read property '0' of undefined" error occurs when trying to access the 0th index in a variable that stores an undefined value. Make sure to initialize the variable to the correct type, e.g. array or string, before accessing the index.
To solve the "Cannot read property 'value' of null" error, make sure you aren't accessing the value property on a null value, e.g. a non-existent DOM element. An element with the provided id does not exist in the DOM, so the getElementById method returns null .
There are three potential causes:
I resolved this issue after checking:
ui-grid.min.css
)ui-grid.min.js
)'ui.grid'
and 'ui.grid.selection'
added to module initialization app = angular.module('app',[
'ui.grid','ui.grid.selection'
])` )<div id="my-grid" ui-grid="gridOptions"
ui-grid-selection
></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With