M
M
Maxim Dunayevsky2014-12-25 15:22:37
Angular
Maxim Dunayevsky, 2014-12-25 15:22:37

Why does $resource.get() make 2 requests?

Hello!
I wrote this service:

app.factory('Company', function($resource){
    return $resource(
        '/api/company/:id/',
        {id : '@id'},
        {update: {method: 'PUT'}}
    );
});

Next, I wrote the controller:
app.controller('CompanyDetailCtrl', function($scope, Company, $routeParams){
    //Делаю инициализацию $scope
    $scope.company = Company.get({id: $routeParams.id}); //id = 2, 3, N
});

I can’t understand why in this case the Company service makes a GET request twice, because there is no second call to the get() method anywhere further down the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Dunayevsky, 2015-12-29
@dunmaksim

Topic closed. The problem is not in the resource, but in the controller. If ngRoute is already used, then the controller must be specified either in the router or in the template, and not in both places.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question