Would someone be able to assist me with storing the data returned by the $http.get
function in a $scope
variable for use in my ui-grid
control?
I have tried the code below but seem to be missing something simple. I just can't figure out what it is:
app.controller('AdminUsersGridCtrl', function ($scope, $http, uiGridConstants) {
$http.get('/api/admin/user')
.success(function (response, $scope) {
$scope.myData = response;
})
.error(function (error) {
console.log(error);
});
console.log($scope.myData);
$scope.gridOptions = {
data: 'myData',
enableFiltering: true,
columnDefs: [
{ field: 'firstName' },
{ field: 'lastName' },
{ field: 'jobTitle'},
{
field: 'email',
filter: {
condition: uiGridConstants.filter.ENDS_WITH,
placeholder: 'ends with'
}
},
{
field: 'phone',
filter: {
condition: function(searchTerm, cellValue) {
var strippedValue = (cellValue + '').replace(/[^\d]/g, '');
return strippedValue.indexOf(searchTerm) >= 0;
}
}
},
]
};
});
When I check the console inside the success function, it prints undefined
. What can I do to access the original $scope
inside the $http.get success
function?