I have a simple search form that passes to a controller that fires an AJAX request to Flickr. Upon receiving the returned data I want to change to another view for display of the results. Everything works fine except that I am unable to pass the JSON data between the two views. I've tried various permutations of state.go('results', {...}
and adding params
to the stateProvider
but this doesn't appear to work for me - as this doesn't appear to be a particularly unusual thing to want to achieve I'm obviously missing something rather daft. Presumably.
Main App.js
var photoApp = angular.module('photoApp', ['infinite-scroll', 'ui.router']);
photoApp.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/home');
$stateProvider
.state('home', {
url: '/home',
templateUrl: '/Client/Views/partial-search.html'
})
.state('results', {
templateUrl: '/Client/Views/partial-results.html',
params: { 'photos': ''}
});
});
Controller
//snip
$scope.processForm = function($stateParams){
//snip
$http({
method: 'JSONP',
url: 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + key + '&text=' + $scope.formData.search + '&extras=owner_name,tags,description',
params: {
'format': 'json',
'jsoncallback': 'JSON_CALLBACK'
}
}).success(function (data) {
$scope.photo = data.photos;
$state.go('results', { 'photos': $scope.photo });
});
};
$scope.loadMore = function () {
// populate an 'infinite scroll in the results page
}
};
};
app.controller("FlickrController", FlickrController);
partial-results.html - builds a four-column grid of images
<div ng-controller="FlickrController">
<div class="row">
<div infinite-scroll='loadMore()' infinite-scroll-distance='2'>
<div ng-repeat='image in images'>
...
In case the flow isn't clear: View 1(searchform) -> processForm()(controller) -> view2 (partial-results.html) -> loadMore() (controller). It's getting the $scope.photos
to be available in the partial-results view that is the issue.