ng-repeat没有更新模型更改

时间:2014-11-14 08:43:07

标签: javascript jquery angularjs angularjs-scope angularjs-ng-repeat

我正在尝试更新模型更改列表,但有时ng-repeat工作,有时它不会,有人可以帮助我,因为这是为什么这是hapenning 我从jQuery调用angular函数代码是:

angular.element($('#updateGroupPannel')).scope().prepareToUpdate(group);

这是被调用的角度函数和角度代码:

$scope.prepareToUpdate = function(group)
{
    $scope.groupId = group.id;
    $scope.usersPageChanged();
    $scope.adminsExistingPageChanged();
}
$scope.usersPageChanged = function()
{
    workbenchService.usersUnderAdminList($scope.currentUserPage).then(function(data)
    {
        $scope.usersExisting = data;
    })
};
$scope.adminsExistingPageChanged = function()
{
    workbenchService.groupAdminsList($scope.currentExistingAdminPage, $scope.groupId).then(function(data)
    {
        $scope.editGroup.admins = data;
    })
};

这是填充用户和管理员列表的html代码:

<form name="GroupUpdate" id="updateGroupPannel" ng-controller="updateController">
    <div ng-repeat="user in editGroup.appUsers track by $index">
       <div class="panel panel-default">
       <div>{{user.name}}</div>
    </div>

    <div ng-repeat="admin in editGroup.admins track by $index">
        <div class="panel panel-default">
            <div>{{admin.name}}</div>
        </div>
    </div>
</form>

问题是有时ng-repeat更新为$ scope.usersExisting但有时它没有得到更新,任何帮助都非常感谢,谢谢

1 个答案:

答案 0 :(得分:0)

我发布了答案,因为它对那些遇到同样问题的人有帮助,这里的问题是承诺没有链接我做了以下更改,现在它工作得很好,

$scope.prepareToUpdate = function(group)
{
    $scope.groupId = group.id;
    $scope.usersPageChanged().then(function(){
        $scope.adminsExistingPageChanged();
    });
}
$scope.usersPageChanged = function()
{
    var promise = workbenchService.usersUnderAdminList($scope.currentUserPage).then(function(data)
    {
        $scope.usersExisting = data;
    })
    return promise;
};
$scope.adminsExistingPageChanged = function()
{
    var promise = workbenchService.groupAdminsList($scope.currentExistingAdminPage, $scope.groupId).then(function(data)
    {
        $scope.editGroup.admins = data;
    })
    return promise;
};