我不明白为什么我的创作者阵列没有绑定。 我尝试将$ scope.setCreators()包装到$ scope中。$ apply我得到了INPROG错误,并且包含在$ timeout中它没有工作。 这是代码:
JS:
$scope.creators = [
{ firstName: 'test', middleName: 'peter', lastName: 'po'}
];
$scope.$on('pageChanged', function(e, data){
if( data.cat !== 'creator' ) return;
$scope.getCreators( data.page );
});
$scope.setCreators = function( creators ){
$scope.creators = creators;
console.log( $scope.creators );
};
$scope.getCreators = function( page ){
var query = {
offset: page * $scope.offset,
limit: $scope.offset
};
$http.post(baseURL+'/creators', query).success(function(data){
$timeout(function() {
$scope.setCreators( data.data.results );
}, 0);
});
};
HTML:
<div ng-controller="CreatorCtrl">
<div ng-repeat="creator in creators">
{{creator.firstName}}
{{creator.middleName}}
{{creator.lastName}}
</div>