Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Angularjs Show (Display) Confirm Dialog Box Example on ng-click Button Event

Jun 22, 2015
Introduction

Here I will explain how to show confirm dialog box message in
AngularJS example using ng-click directive or show / display JavaScript dialog confirm message box with example in AngularJS using ng-click with example. Generally in JavaScript we will use “window” property to show confirm dialog box same way in AngularJS we will use “$window” property show confirm dialog message box.

Description:
  
In previous articles I explained Angularjs show hide div on checkbox selection,
Angularjs refresh div for every 1 second using interval mode, Angularjs convert number to currency format, Angularjs get dropdownlist selected value, Angularjs convert text to uppercase while typing and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to show confirm dialog box message in AngularJS with example using ng-click directive.

To show confirm box in AngularJS we need to write the code like as shown below


$scope.showconfirmbox = function () {
if ($window.confirm("Do you want to continue?"))
$scope.result = "Yes";
else
$scope.result = "No";
}

If you want to check it in complete example you need to write the code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Angularjs Show JavaScript Confrim Message</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var myapp = angular.module('sampleapp', []);
myapp.controller("sampleController", function ($scope, $window) {
$scope.showconfirmbox = function () {
if ($window.confirm("Do you want to continue?"))
$scope.result = "Yes";
else
$scope.result = "No";
}
})
</script>
</head>
<body>
<form id="form1">
<div data-ng-app="sampleapp" data-ng-controller="sampleController">
<input type="button" value="Show Confirm Box" ng-click="showconfirmbox()" />
<span>Your Answer:<b>{{result}}</b></span>
</div>
</form>
</body>
</html>

Live Demo

For live demo click below button to show confirm box


Your Answer:{{result}}


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

3 comments :

Unknown said...

Thank you Suresh bhai, it's help me out...

Anonymous said...

How can i open modal popup confirm box in angular

viji venkatesh said...

Thank you so much. You saved my time.

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.