B
B
Bogdan Bembenok2016-10-06 15:17:49
JavaScript
Bogdan Bembenok, 2016-10-06 15:17:49

Why do all resovle (ui-router) trigger on application start?

Ideally, as far as I understand, the resolver should work only when you go to a certain state, to which, accordingly, this resolver is attached.
everything is going to one file in my gallop, and it works during initialization, then when switching to another state, its resolve works again. It turns out requests are sent twice.
For example, threw off the state

.state('events.feed', {
        url: '/feed',
        templateUrl: "/views/events/feed.html",
        controller: "eventsFeedController",
        resolve: {
          position: function($geolocation, appRestAPI) {
            console.log('Call POS from FEED');
            var coords = [];
            return $geolocation.getCurrentPosition().then(function(position) {
              coords[0] = position.coords.latitude;
              coords[1] = position.coords.longitude;
              return coords;
            }).catch(function(err){
              coords[0] = appRestAPI.testCoords.lat;
              coords[1] = appRestAPI.testCoords.lng;
              return coords;
            })
          },
          events: function(eventsService, position) {
            debugger;
            console.log('Call from FEED');
            return eventsService.getEvents(position).then(function(data) {
              return data.data.events;
            })
          }
        }				
      })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bogdan Bembenok, 2016-10-17
@b_e_m

I found the reason, on the run'e of the main module there was a redirect to the events.feed state, which worked and loaded the resolve.
Then immediately there was an inconspicuous redirect to the main one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question