Introduction:
Here I will explain how to show alert message in AngularJS or show / display JavaScript alert box or message in AngularJS using ng-click with example. Generally in JavaScript we will use “window” property to show alert message same way in AngularJS we will use “$window” property show alert message.
Description:
In previous articles I explained Angularjs convert number to currency format, Angularjs get dropdownlist selected value, Angularjs convert text to uppercase while typing, Angularjs refresh div for every 1 second using interval mode, 5 + Angularjs Gridview and table plugin examples with demos and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to show alert message in AngularJS.
In previous articles I explained Angularjs convert number to currency format, Angularjs get dropdownlist selected value, Angularjs convert text to uppercase while typing, Angularjs refresh div for every 1 second using interval mode, 5 + Angularjs Gridview and table plugin examples with demos and many articles relating to AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to show alert message in AngularJS.
|
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 Alert 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("expressionController",
function ($scope,$window) {
$scope.showalertmessage = function
() {
if ($scope.username == undefined)
$window.alert('Please Enter Username')
else
$window.alert('Entered Name is : '
+ $scope.username)
}
})
</script>
</head>
<body>
<form id="form1">
<div data-ng-app="sampleapp"
data-ng-controller="expressionController">
Enter Name : <input type="text" ng-model="username" />
<input type="button"
value="Show
Alert" ng-click="showalertmessage()" />
</div>
</form>
</body>
</html>
|
Live
Demo
For
live demo enter text in below textbox and click below button to see alert
message
|
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. |
|||
|
|||
1 comments :
Good code, but i want by default get value alert show data
Note: Only a member of this blog may post a comment.