Reload same view with different data


#1

Hello , I am using ionic and I have the following issue.

I have a search in the ion-nav-bar and i have function that $state.go to a state with resolve

.state('tab.textSearch', {
  url: '/textSearch/:searchText',
  resolve: {
    getSearchTextData : function(TextSearchData,$stateParams) {
        TextSearchData.emptyData();
        console.log('LoadDataFromResolve');
        return TextSearchData.getTextSearchData($stateParams.searchText);
    }
  },
  views: {
    'tab-home': {
      templateUrl: 'templates/tab-textSearch.html',
      controller: 'TextSearchCtrl'
    }
  }
});

In the TextSearchData factory I have the following thing:

myTextSearchResults.getTextSearchData = function(textSearchData) {
    $http.get("http://domain?search="+ textSearchData).success(function (d) {
      textData=d;
      console.log('loadDataFromQuery');
      deffered.resolve(d);
    });
    return deffered.promise;
  };

And my controller looks like that:

.controller('TextSearchCtrl', function($scope,$rootScope,getSearchTextData,TextSearchData) {
  console.log('LoadDataInController');
  $scope.searchItem=getSearchTextData;
})

So the first time I call the function It consoles:

1.LoadDataFromResolve
2.loadDataFromQuery
3.LoadDataInController

And everything is fine with the results,
but when I am on the result screen - tab-textSearch.html and try to make another search it consoles
1.LoadDataFromResolve
2.LoadDataInController
3.loadDataFromQuery

Does anyone know how could i fix that? Any help will be appreciated.


#2

Ok i saw where’s the problem i had to put the deffer inside the function

myTextSearchResults.getTextSearchData = function(textSearchData) {
var deffered = $q.defer();
$http.get("http://bazar.bg/api/ads/search?search="+ textSearchData).success(function (d) {
  textData=d;
  console.log('loadDataFromQuery');
  deffered.resolve(d);
});
return deffered.promise;

};