简体   繁体   English

价值不变

[英]Value doesn't change $on

I have an issue working on this https://github.com/poillic/marvelApi/tree/master/server 我在处理此https://github.com/poillic/marvelApi/tree/master/server时遇到问题

I need to update my pagination when I recieve the datas but my $scope.creators array doesn't seems to be modified. 接收数据时,我需要更新分页,但是$ scope.creators数组似乎没有被修改。

Here is the code : 这是代码:

$scope.creators = [ { firstName: 'test', middleName: 'peter', lastName: 'po'} ];


$scope.setCreators = function( creators ){
    console.log(creators);
    $scope.creators = creators;
};

$scope.getCreators = function( page ){
    var query = {
        offset: page * $scope.limit,
        limit: $scope.limit
    };

    console.log( query );

    $http({
        url : baseURL+'/creators',
        params : query,
        method : "GET"
    }).success(function(data){
        if( data.data.results ){
            $scope.setCreators( data.data.results );
        }

        $scope.total = data.data.total;
        $scope.nbPages = ($scope.total / $scope.limit) | 0;

        var pageData = { 
            total: $scope.total,
            limit: $scope.limit
        };
        $scope.$broadcast( 'pagination', pageData );
    }).error(function(){
        console.log('Get creators error');
    });
};

$scope.getCreators(0);

$scope.$on('pageChanged', function(e, data){
    $scope.getCreators( data.page );
});

The first $scope.getCreators() is called everything works fine. 第一个$scope.getCreators()称为一切正常。 But in $scope.$on it looks like a $scope.creators is modified but not the good one. 但是在$scope.$on看起来像是$scope.creators被修改了,但不是好的。

Answer found with the help of GPicazo. 在GPicazo的帮助下找到了答案。

The problem that I defined two controller for the same view. 我为同一视图定义了两个控制器的问题。 One time in the html view and another time in the routes. 一次在html视图中,另一次在路由中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM