我有一个修改按钮,当我想点击它时,将执行modify()函数,文本按钮将变为save,我点击它,将执行save()函数。
这些是代码
<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"
}
我想执行第一次点击modify(),并在第二次点击save()。
我认为我应该使用第三个功能,但我不知道如何使用!
谁能帮我 ?
你是对的,你的控制器需要第三个功能,它在修改和保存之间切换。应该很简单:
$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();
}
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句