S
S
Seva2015-08-01 22:57:49
JavaScript
Seva, 2015-08-01 22:57:49

Why is the function being executed twice?

EventService.getDataFromDB().then(function(result) {
        if (result.length > 0) {
            $scope.items = EventService.populateData(result).items
            $scope.categories = EventService.populateData(result).categories
            console.log('Готово (база)!');
        } else {
            EventService.getDataFromApi().then(function() {
                EventService.getDataFromDB().then(function(result) {
                    $scope.items = EventService.populateData(result).items
                    $scope.categories = EventService.populateData(result).categories
                    console.log('Готово (API)!');
                })
            })
        }
    });

For some reason, this piece of code is executed twice - the news is duplicated, the message falls out twice in the console. There are no more calls anywhere, what's the matter? Broke my head.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sanex3339, 2015-08-01
@sanex3339

https://ru.wikipedia.org/wiki/%D0%A0%D0%B5%D0%BA%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question