On Saturday, February 8, 2014 5:19:32 PM UTC-8, David Karr wrote: > > I'm assembling my first AngularJS app. I define a service that uses > $resource to make a REST service call. I inject that service into my > controller and make a query on it, and I wrap that in the $interval service > to call it once every 5 minutes. At least that's what I'm intending. When > I run this with firebug I suddenly see a gazillion requests to the REST > service. I must be misunderstanding something. > > Here's my elided HTML: > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " >> http://www.w3.org/TR/html4/loose.dtd"> >> <html ng-app="DiagApp"> >> <head> >> <meta http-equiv="Content-Type" content="text/html; >> charset=ISO-8859-1"> >> <title>Diagnostics</title> >> <link href="// >> netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" >> rel="stylesheet"> >> </head> >> <body ng-controller="DiagCtrl"> >> <h1>Diagnostics</h1> >> <tabset> >> <tab heading="Data Sources"> >> <div ng-repeat="dataSource in dataSources"> >> </div> >> </tab> >> <tab heading="Queries"> >> </tab> >> <tab heading="Handlers"> >> </tab> >> <tab heading="Workflow Mappings"> >> </tab> >> <tab heading="Performance Thresholds"> >> </tab> >> <tab heading="Configuration"> >> </tab> >> </tabset> >> <script src="// >> ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.js"></script> >> <script src="// >> ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular-resource.js >> "></script> >> <script src="/js/app/diagapp.js"></script> >> <script src="/js/app/libs/ui-bootstrap-tpls-0.10.0.js"></script> >> </body> >> </html> >> > > Here's my elided diagapp.js: > > var diagapp = angular.module("DiagApp", ['ui.bootstrap', 'ngResource']); >> >> diagapp.factory('DataSources', ['$resource', function($resource) { >> return >> $resource('http://<hostportandpath>/service/diagnostics/datasourceStatus.json', >> >> {}, {}); >> }]); >> >> diagapp.controller("DiagCtrl", ['$scope', '$interval', 'DataSources', >> function($scope, $interval, DataSources) { >> var datasourcesInterval = $interval(function() { >> $scope.dataSources = DataSources.query(function() { >> }, 300000); >> }); >> $scope.$on('$destroy', function() { >> $interval.$cancel(datasourcesInterval); >> }); >> }]); >> >> > What particular dumb mistake am I making that is making it call the > service much more than I expect? > > Ok, after looking closer at that "$interval" call, I see where I messed that up. I ended up sending the "300000" to the "query" function, not the "$interval" function.
-- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
