$http calls with angular routes

petermosquito

New Member
I just setup routes in my angular app. The first view, \[code\]List\[/code\] makes an http call to get a list of presentations\[code\]function ListController($scope, $http){ $scope.error = null; $scope.presentations = null; $scope.requesting = true; $scope.currentTitle = '-1'; $data = http://stackoverflow.com/questions/15580692/{'type' : 'presentations' }; $http.post('resources/request.php', $data, {timeout:20000}) .success(function(data, status, headers, config) { $scope.requesting = false; $scope.presentations = data; }) .error(function(data, status, headers, config) { $scope.requesting = false; log(status + ', data:" ' + data + '"'); } } );}\[/code\]My route is\[code\]angular.module('main',[]). config(function($routeProvider) { $routeProvider. when('/', {controller:ListController, templateUrl:'resources/views/list.html'}). when('/view/:id', {controller:VforumController, templateUrl:'resources/views/vforum.html'}). otherwise({redirectTo:'/'}); });\[/code\]the problem I have is when I go to \[code\]#/view/:id\[/code\] and then back to \[code\]/\[/code\] the \[code\]$http\[/code\] call gets called again. How can I make it so it only loads the first time going into the app and reference the same data that was loaded the first time?I attempted to create a variable outside of angular and set it equal to the data loaded the first time. Then, in the \[code\]ListController\[/code\] basically did a \[code\]if data is null, do the $http call else set $scope.data = http://stackoverflow.com/questions/15580692/data\[/code\] but that didn't work. The list view was just blank. \[code\]$scope.data\[/code\] is what builds my list.
 
Back
Top