我正在尝试为我的网站用户创建一个“确认”按钮,以便他们在单击按钮时看到,并且我正在使用 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/