javascript - Angularjs 类确认按钮

标签 javascript angularjs angularjs-scope

我正在尝试为我的网站用户创建一个“确认”按钮,以便他们在单击按钮时看到,并且我正在使用 angularJS 类。我的代码如下:

class TodosListCtrl {
  constructor($scope, $window){
    $scope.viewModel(this);
    this.$scope = $scope;
  }
//... a bunch of functions
  Clear(){
    var delete = this.$scope.confirm("Are you sure you want to clear the text?");
    if(delete){
      //delete stuff
  }
}

但是每次我单击调用“Clear()”函数的按钮时,都会收到错误

"this.$scope.confirm is not a function at TodosListCtrl.Clear"

有谁知道为什么会发生这种情况,以及如何解决这个问题?

最佳答案

只需将 this.$scopethis.$scope.confirm 中删除即可:

class TodosListCtrl {
  constructor($scope, $window){
    $scope.viewModel(this);
    this.$scope = $scope;
  }
//... a bunch of functions
  Clear(){
    var delete = confirm("Are you sure you want to clear the text?");
    if(delete){
      //delete stuff
  }
}

关于javascript - Angularjs 类确认按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42056932/

相关文章:

javascript - 无法访问 angular.js Controller 中的变量

javascript - 使用 $scope AngularJS 仅显示数组中的最新值

javascript - Chrome 控制台中的 regExp 奇怪 react

javascript - 我可以更改使用本地日期输入的日期格式吗?

Angularjs 在指令中获取表单字段有效性

javascript - 无法使用 Angular.merge() 合并对象

javascript - angularjs-一个 Controller 在另一个 Controller 中的调用方法

javascript - JS 函数通过生成的值用唯一元素填充数组

javascript - 如何使用 express js 创建一个简单的 html 服务器

node.js - 如何将 MEAN 堆栈部署到我的托管服务器?