State resolution every time

So, I'm trying to wrap my head around how the router works in 0.2.0. I have created my states, I have permission to my state when you go to the URL. What I find difficult to determine how best to do is to load my data each time this state goes to.

the router

$stateProvider
    .state('admin.levels',{
        url: '/levels',
        templateUrl: 'views/admin/levels/index.html',
        resolve: {
            levelData: function($q,Levels){
                var deferred = $q.defer();
                Levels.query(function(levels) {
                    console.log('resolving state');
                    deferred.resolve(levels);
                });

                return deferred.promise;
            }
        },
        controller: 'AdminLevelsController'
    })
    .state('admin.levels.create',{
        url: '/create',
        templateUrl: 'views/admin/levels/create.html',
        controller: 'AdminLevelsController'
    })

controller

'use strict';

angular.module('mean.levels').controller('AdminLevelsController', ['$scope', '$state','$stateParams', '$location', 'Global', 'Levels','levelData', function ($scope, $state,     $stateParams, $location, Global, Levels, levelData) {

    $scope.new = function(){
        var level = new Levels({
            title: this.title,
            content: this.content
        });

        level.$save(function(response){
            $state.go('admin.levels');
        });
    };
}]);

, Angular . , "", . , , , new(), admin.levels. , , , . , - , , .

, , , , , , .

.

+3
1

, . question - . , , , , . , , :

level.$save(function(response){
    $scope.levels.push(response);
    $state.go('^');
});

, , , , . , , .

0

All Articles