ng-bind-html 不更新记录 angularjs 1.6
ng-bind-html does not update the record angularjs 1.6
无法重新加载 html 中的数据(查看)
它仅在第一次(页面加载)时加载正常,点击按钮时它不会反映更改,尽管控制器有正确的记录。
查看-
<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_Quizes 函数。 Angular 使用 $scope
将视图绑定到控制器。还要从 ng-repeat="Question in ::qstns"
中删除 ::
,因为它用于单向绑定。如果您使用单向绑定,控制器中发生的任何 qstns 更改都不会反映在视图中。
$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.');
});
}
无法重新加载 html 中的数据(查看)
它仅在第一次(页面加载)时加载正常,点击按钮时它不会反映更改,尽管控制器有正确的记录。
查看-
<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_Quizes 函数。 Angular 使用 $scope
将视图绑定到控制器。还要从 ng-repeat="Question in ::qstns"
中删除 ::
,因为它用于单向绑定。如果您使用单向绑定,控制器中发生的任何 qstns 更改都不会反映在视图中。
$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.');
});
}