ng-repeat没有更新

时间:2017-11-03 00:20:22

标签: javascript angularjs

提交以下表单时,会在数据库中创建其他条目。但ng-repeat没有得到更新。 有什么想法吗?

html代码:

                                
                                

                                <table class="redTable">
                                    <thead>
                                        <tr>
                                            <th> Domain</th>
                                            <th> Username</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <tr ng-repeat="eachuserconfigdata in userconfigdata track by $index">
                                            <td>
                                                <input type="text" ng-model="eachuserconfigdata.Domain" value="{{ eachuserconfigdata.Domain }}" ng-readonly='!($index == eEditable)' ng-dblclick="eEditable = $index" style="background-color: transparent ; width:80px;border: 0;" />
                                            </td>
                                            <td>
                                                <input type="text" ng-model="eachuserconfigdata.UserName" value="{{ eachuserconfigdata.UserName }}" ng-readonly='!($index == eEditable)' ng-dblclick="eEditable = $index" style="background-color: transparent ; width:80px;border: 0;" />
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>

                                <br />
                            </div>

的Javascript var myApp = angular.module(“mymodule”,['ngMaterial']);

var myController = function($ scope,$ http,$ log){

$scope.username = "";
$scope.ps = "";                         

$scope.submit = function () {
    //alert($scope.username);
    //alert($scope.ps);

    $scope.myStyle = { color: 'red' };
    var data = {            
        Domain: $scope.domainname,
        UserName: $scope.domainusername,
        Password: $scope.domainps
    };
    $http({
        method: 'POST',
        //url: 'Login/LoginUser?user=' + $scope.username + '&password=' + $scope.ps,
        url: 'Login/UpdateDomainConfiguration',
        data: data,
        headers: { "Content-Type": "application/json" }
    })
        .then(function successCallback(response) {
            var userid = 0;
            $scope.message = response.data;  
            //$log.info(response);                               
            $scope.GetUserConfigDetails();

        }, function errorCallback(response) {
            // called asynchronously if an error occurs
            // or server returns response with an error status.
            alert(response.data);
        });                
}

1 个答案:

答案 0 :(得分:0)

你根据你的代码所做的是你刚把它保存到数据库但从未提取过它(不确定这个$scope.GetUserConfigDetails();)。

您需要做的是将其保存到db后,再次获取数据并将其分配给ng-repeat阵列。或者您只需将已保存的数据插入到现有数组中,这样就不必再次获取。