NG-BIND-HTML不会更新记录AngularJS 1.6



无法在html(view)

中重新加载数据

仅在第一次加载(页面加载),按钮单击它没有反映更改,尽管控制器具有正确的记录。

视图 -

<div class="well" ng-app="myQuizApp"> <fieldset ng-repeat="Question in ::qstns">
 </fieldset> </div>
<button type="button" class="btn btn-primary btn-lg btn-block" ng-click="Load_Quizes('2')">Review</button>

Anguar JS图书馆在此处进行了审查1.6

myApp.controller("myQuizs", function ($scope, angularService, $window, $sce,$interval) {
var action = 'qiz1';
Load_Quizes(1); // Triggering page load (working fine)
// While calling the function in button click , it gets triggered and contains correct data but ng-repeat does not updates (holds old records) .
    function Load_Quizes(qtnserial) {
        var getQuzData = angularService.LoadQuizes(action, qtnserial);
        getQuzData.then(function (response) {
            try {
                //LOAD QUESTION CHOICE                
                if (response.data != null) {
                    debugger;
                    $scope.Quiz = response.data;
                    if ($scope.Quiz.Quiz_id > 0) {
                        $scope.qst_toask = $scope.Quiz.Quiz_Name.split('"').join('');
                        $scope.qstns = $scope.Quiz.QuizQuestiones;
                    } else {
                        $window.alert("Online mock test / Quiz does not exists.");
                    }
                }
                else {
                    $window.alert("Online mock test / Quiz does not exists.");
                }
            }
            catch (e) {
                $window.alert('Quiz response error.');
            }
        }, function () {
            alert('Error in getting records.');
        });
    }

请帮忙。谢谢。

您需要在 $scope上定义load_quize函数。Angular使用$scope将视图绑定到控制器。还可以从ng-repeat="Question in ::qstns"中删除::,因为它用于一种方式绑定。如果您使用一种绑定,则在控制器中发生的QSTN的任何更改都不会反映在视图中。

$scope.Load_Quizes(1);
$scope.Load_Quizes(qtnserial) {
    var getQuzData = angularService.LoadQuizes(action, qtnserial);
    getQuzData.then(function (response) {
        try {
            //LOAD QUESTION CHOICE                
            if (response.data != null) {
                debugger;
                $scope.Quiz = response.data;
                if ($scope.Quiz.Quiz_id > 0) {
                    $scope.qst_toask = $scope.Quiz.Quiz_Name.split('"').join('');
                    $scope.qstns = $scope.Quiz.QuizQuestiones;
                } else {
                    $window.alert("Online mock test / Quiz does not exists.");
                }
            }
            else {
                $window.alert("Online mock test / Quiz does not exists.");
            }
        }
        catch (e) {
            $window.alert('Quiz response error.');
        }
    }, function () {
        alert('Error in getting records.');
    });
}

最新更新