我正在尝试为我网站的用户创建一个“确认”按钮,以查看他们何时单击按钮,并且我正在使用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.$scope中删除​​this.$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/

10-11 22:14
查看更多