2017-02-05 29 views
0

我想爲我的網站的用戶創建一個「確認」按鈕,以查看他們何時單擊按鈕,並且我正在使用angularJS類。我的代碼如下: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 
    } 
} 

但每次我點擊調用按鈕時「清除()」函數,我得到的錯誤

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

有誰知道爲什麼發生這種情況,以及我如何解決這個問題?

+2

我想你只需要採取'這個$ scope'掉這個'$ scope.confirm' –

+0

這一工作。!謝謝,我沒有意識到這很簡單。 –

+1

沒問題,當他們那麼簡單時,我喜歡它! –

回答

1

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