I have this poller function that polls data every 10000ms which is fine, however I need to be able to access variable from outside so that I can use splice
function.
code for service:
'use strict';
//service to get data for analytics page
angular
.module ('myApp')
.factory('Analyticshistory', function ($resource) {
return $resource('analytics_history.json',{}, {'query': {method: 'GET', isArray: false}});
});
code for controller:
'use strict';
angular
.module('myApp')
.controller('analyticshistoryCtrl', ['$scope', 'poller', 'Analyticshistory', function ($scope, poller, Analyticshistory) {
var dataToSplice;
var pollerAnalyticsHistory;
pollerAnalyticsHistory = poller.get (Analyticshistory, {delay: 10000});
pollerAnalyticsHistory.promise.then (null, null, function (data) {
//this works fine but it splices
//data every 10000ms which is not good
$scope.myData = data.analytics.splice(0,5);
//I'm trying this to access this outside
$scope.myData = data.analytics;
dataToSplice = $scope.myData;
});
//outside the poller here I want to access data and splice them
//to pass them into to ng-grid
dataToSplice.splice(0,5);//this does not work
$scope.myData.splice(0,5);//this doe not work either
$scope.gridOptions = {
data: 'myData',
columnDefs: 'columns'
}
}]);
what am I doing wrong here?
many thanks for help
PLUNKER: http://plnkr.co/edit/ui279rL9JZvxgUJXlkLB?p=preview