简体   繁体   中英

AngularJS: Different callbacks on clicking okay on the confirmation dialog

I have not worked with AngularJS much, I have a question, there are multiple buttons which open the same confirmation dialog box, but based on clicking on which button, dialog box opened, I need to do something different for each buttons. How can we achieve this without using any anti-patterns. Currently I declare a method and change its definition before showing a dialog.

 $scope.onClickButton1 = function() { $scope.submitDialog = function() { //do something specific when submitting for button1 } $scope.showDailog = true; } $scope.onClickButton2 = function() { $scope.submitDialog = function() { //do something specific when submitting for button2 } $scope.showDailog = true; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>

Html:

<button ng-click="onBtn1Click(); openDailog();"> Btn1 </button>
<button ng-click="onBtn2Click(); openDailog();"> Btn2 </button>

Controller:

$scope.onBtn1Click= function(){
   //do something on btn1 click;
}


$scope.onBtn2Click= function(){
   //do something on btn2 click;
}


$scope.openDailog= function(){
   $scoope.showDailog =true;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM