Angularjs类确认按钮

时间:2017-02-05 20:29:06

标签: 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"

有谁知道为什么会这样,以及我如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

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
  }
}