2017-02-05 4 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.$scope.confirmのオフthis.$scopeを取る:

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 
    } 
} 
関連する問題