My goal is to switch views within the Search controller after receiving search results from the server through $http. However, my current approach doesn't seem to be working as intended. I also need to pass the response to the new view for displaying the results properly.
In my app.js:
.....state('tab.search', {
url: '/search',
views: {
'tab-search': {
templateUrl: 'templates/tab-search.html',
controller: 'SearchCtrl as search'
}
}
})
.state('tab.search-results', {
url: '/results',
views: {
'tab-search-results': {
templateUrl: 'templates/tab-search-results.html',
controller: 'SearchResultsCtrl as searchResults'
}
}
})
My Search controller contains:
.controller('SearchCtrl', function($scope, $state, $location, $ionicPopup, service) {
....
$scope.doSearch = function(state) {
.....
var result = service.doSearch(dataObj);
result.then(function(response) {
console.log("I'm here");
$state.go('tab.search-results');
......
The basic structure of my search results view (tab-search-results.html) looks like this:
<ion-view view-title="Search Results">
<ion-content padding="true">
hello world
</ion-content>
</ion-view>
This setup is similar to my other pages/views as well.
Upon performing a search, the console message appears and the URL changes to /results according to the tab.search-results state, however, the template/view does not change or display.
If I modify $state.go('tab.search-results'); to target another app state/view that works, it functions correctly. It seems that there is an issue with this specific state/view.
If there is a more effective way to achieve the same outcome or if you have any suggestions on how to pass the "response" from SearchCtrl to SearchResultsCtrl, please advise. Any help is greatly appreciated.
Thank you.