0

I am using Ui-Route in angular js, and I want to call $http service on every state change. When I inject $http service in statechange event it gives an error of circular dependency or even I inject in interceptor the same error is showing. Please help me with this.

Thank you

Gonzalo.-
  • 12,512
  • 5
  • 50
  • 82
  • 1
    this link may help you http://stackoverflow.com/questions/20230691/injecting-state-ui-router-into-http-interceptor-causes-circular-dependency – Mr.7 Sep 27 '16 at 05:41

1 Answers1

0

You can put the service call in resolve for state

$stateProvider
    .state('business-page', {
        url: '/your-listing/:id',
        controller: 'BusinessCtrl as vm',
        templateUrl: 'pages/business/business.html',
        title: 'Details',
        resolve: {
            listing: ['appDataFactory', '$stateParams', function (appDataFactory, $stateParams) {
                return appDataFactory.getListingData($stateParams.id);
            }]
        }
    })

where appDataFactory will be the service for $http request and the response can be solved as injection on the state controller