我的 Controller 中有一个名为 this.selectedCourses
的数组。该数组有一些项目在我的 View 中显示为列表。
经过一些步骤后,我得到了这个:
this.checkAddedCourses = function(studentCourses){
...
if(repeatedCourses.length != 0){
sweetAlert({
title: title,
text: text + ' ' + courseList,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: confirmButtonText,
closeOnConfirm: false,
html: true
},
function(){
angular.forEach(repeatedCourses, function(repeatedCourse){
this.removeCoursePurchase(repeatedCourse);
}.bind(this));
swal("Deleted!", "Your purchase has been refreshed.", "success");
}.bind(this));
}
}
当用户单击“删除”按钮时,项目将从数组中很好地删除,我已经检查过,但在我看来,在我对该数组执行某些操作之前,我仍然会看到这些项目。就像删除元素后没有刷新数组一样。
谢谢。
PD:sweetAlert 是一个警报库。
最佳答案
使用 $scope 而不是它来在您的 View 上进行数据绑定(bind) - 所以 $scope.selectedCourses。请记住将 $scope 作为依赖项传递到 Controller 中。
关于javascript - 函数执行后 View 中没有更新 $scope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29819864/