A
A
Artem Komarov2015-02-10 16:01:21
Angular
Artem Komarov, 2015-02-10 16:01:21

AngularJS, IonicFramework why does the controller work only the first time?

The controller itself:

.controller('FavsCtrl', function($scope, $http, Clubs) {
        $scope.favs = Clubs.getFavs();
        if ($scope.favs.length) {
            $http.get('http://localhost:6789/club/' + $scope.favs.join(",")).success(function(data, status, headers, config) {
                $scope.favs = data;
            }).error(function(data, status, headers, config) {
                alert('Error '+status+', data is: '+data);
            }).finally(function(data) {
            });
        } else {
            alert('Нет избранного');
        }
    }
})

Route:
.state('tab.favs', {
                url: '/favs',
                views: {
                    'tab-favs': {
                        templateUrl: 'templates/tab-favs.html',
                        controller: 'FavsCtrl'
                    }
                }
            })

Factory:
.factory('Clubs', function() {
        return {
            getFavs: function() {
                var favs = localStorage.getItem("favs");
                return (favs ? JSON.parse(favs) : []);
            }
        }
    });

As a result, when traveling through the routes, it turned out that the controller method only works for the first time, despite the change in the selected and, accordingly, the return value of the factory. It only fires when the page is refreshed (which is not good, because the application will be compiled for mobile platforms). Tell me, please, CHYADNT, colleagues?
PS I tried to do it like here , it did not help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-02-12
@m0sk1t

And what version? They typed a cache there ... so you need to catch events or disable caching.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question