Javascript Angularjs类确认按钮
我试图创建一个“确认”按钮,让我的网站的用户在点击按钮时看到,我使用的是angularJS类。我的代码如下:Javascript Angularjs类确认按钮,javascript,angularjs,angularjs-scope,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
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"
有人知道为什么会发生这种情况,以及我如何解决这一问题吗?只需将
此。$scope
从此。$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
}
}
我想你只需要把this.$scope
从this.$scope中去掉就行了。确认成功了!谢谢,我不知道这么简单。没问题,我喜欢这么简单!