javascript - 函数执行后 View 中没有更新 $scope

标签 javascript arrays angularjs data-binding

我的 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/

相关文章:

javascript - 从 AJAX 创建时卡住 Bootstrap

c++ - 如何将二进制输入存储在 C++ 数组中

angularjs - 无法通过 npm 安装 gulp-jshint

angularjs - 使用 ngTagsInput 自动完成无法读取未定义的属性 'then'

javascript - 检查 contenteditable div 中的元素(文本)是否已被删除

javascript - 请更正这个 xpath 表达式

javascript - 从 MongoDB 子文档中的父级检索值

php - 需要有关 mysql_fetch_array() 错误的帮助吗?

c - sscanf 替换以前的值

angularjs - 在AngularJS中,每个都需要捕获吗?