Javascript AngularJS-使用ng click非顺序调用两个函数

Javascript AngularJS-使用ng click非顺序调用两个函数,javascript,angularjs,Javascript,Angularjs,我有一个修改按钮,当我想点击它时,将执行修改()功能,文本按钮将变为保存,我点击它,将执行保存()功能 这些是代码 <button class="btn btn-primary" ng-click="modify(); save()" ng-disabled="!modifyDisabled">{{button}}</button> $scope.button="Modifier" $scope.modify=function(){ $scope.button="E

我有一个修改按钮,当我想点击它时,将执行修改()功能,文本按钮将变为保存,我点击它,将执行保存()功能

这些是代码

<button class="btn btn-primary" ng-click="modify(); save()" ng-disabled="!modifyDisabled">{{button}}</button>

$scope.button="Modifier"
$scope.modify=function(){
  $scope.button="Enregistrer"
  $http.get("http://localhost:5000/settings").then(function(response){
    $scope.settingsInserted = false 
    $scope.nbOperateurPresents= response.data.data[0].nbOperateurPresents
    $scope.targetAmount1stHour= response.data.data[0].targetAmount1stHour
    $scope.targetAmount2ndHour= response.data.data[0].targetAmount2ndHour
    $scope.targetAmount3rdHour= response.data.data[0].targetAmount3rdHour
    $scope.targetAmount4thHour= response.data.data[0].targetAmount4thHour
    $scope.targetAmount5thHour= response.data.data[0].targetAmount5thHour
    $scope.targetAmount6thHour= response.data.data[0].targetAmount6thHour
    $scope.targetAmount7thHour= response.data.data[0].targetAmount7thHour
    $scope.targetAmount8thHour= response.data.data[0].targetAmount8thHour
   })  
}

$scope.save=function(){
 console.log('saved')
 $scope.button="Modifier"
}
{{button}
$scope.button=“修饰符”
$scope.modify=function(){
$scope.button=“Enregister”
$http.get(“http://localhost:5000/settings)然后(函数(响应){
$scope.settingsInserted=false
$scope.NBOperateRpresents=response.data.data[0]。NBOperateRpresents
$scope.targetAmount1stHour=response.data.data[0]。targetAmount1stHour
$scope.targetAmount2ndHour=response.data.data[0]。targetAmount2ndHour
$scope.targetAmount3rdHour=response.data.data[0]。targetAmount3rdHour
$scope.targetAmount4thHour=response.data.data[0]。targetAmount4thHour
$scope.targetAmount5thHour=response.data.data[0]。targetAmount5thHour
$scope.targetAmount6thHour=response.data.data[0]。targetAmount6thHour
$scope.targetAmount7thHour=response.data.data[0]。targetAmount7thHour
$scope.targetAmount8thHour=response.data.data[0]。targetAmount8thHour
})  
}
$scope.save=function(){
console.log('saved')
$scope.button=“修饰符”
}
我想在第一次单击时执行修改(),在第二次单击时执行保存()

我想我应该使用第三个函数,但我不知道如何使用


谁能帮我?

你说得对,你的控制器需要第三个功能,可以在修改和保存之间切换。应该很容易:

$scope.alreadyModified = false;

$scope.modifyFirstAndThenSave = function() {
  if (!$scope.alreadyModified) {
    $scope.alreadyModified = true;
    $scope.modify();
  } else {
    $scope.alreadyModified = false; // just in case a third click should modify again
    $scope.save();
  }
};

但是我有一个问题,你能解释一下你做了什么吗?我把以前的状态存储在一个变量中。因此,当我决定调用哪个操作(修改/保存)时,我能够尊重这个值。在本例中,我将变量从true改为false,反之亦然。您还可以通过一行代码实现这一点:
$scope.alreadyModified=$scope.alreadyModified
因为这里有一个布尔值(true/false),所以我们可以(使用前导的
)对前面的值求反。