我正在努力创建一个"确认"我的网站用户按钮,看他们点击按钮,我正在使用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"
有谁知道为什么会这样,以及我如何解决这个问题?
答案 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
}
}