Service unable to fetch data if traversing it via $state.go in ionic


#1

Following is a very simple method in AnotherCtrl -

$scope.clickbtn = function() {
    $state.go('app.mystate', {id: id, type: type});
};

Now in Ctrl for app.state following is how my controller looks like -

.controller('mystateDetailCtrl', function($scope, $stateParams, stateService, LoaderService) {
    console.log("----------- mystateDetailCtrl ------------");

    var id = $stateParams.id;
    var type = $stateParams.type;
    stateService.getDataByIdAndType(id, type).success(function(data){
      LoaderService.hide();
      console.log("DATA TRR: ", JSON.stringify(data[0]));
      $scope.setdata = data;
    });
});

Now the problem is If I am going through the URL via ng-href is getting the data from the controller, but on click of clickbtn though its coming to this page and console console.log("----------- mystateDetailCtrl ------------"); but unable to fetch data from getDataByIdAndType in the mean time. let me know what I am doing wrong.

.factory('stateService', function(RESURL,$http,LoaderService) {
    return {
        getDataByIdAndType: function(id, type) {
          var url = RESURL+"fetchdata/"+id+"/type/"+type;
          LoaderService.show("Loading Content.. <br>Please wait!");
          var req = {
            method: 'GET',
            url: url
          };
          return $http(req);
        }
    }
});