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

Angularjs Show JavaScript Alert Message (Box) on ng-click with Example

May 6, 2015

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.

To show alert message in AngularJS we need to write the code like as shown below

$scope.showalertmessage = function () {
if ($scope.username == undefined)
$window.alert('Please Enter Username')
$window.alert('Entered Name is : ' + $scope.username)

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

<html xmlns="">
<title>Angularjs Show JavaScript Alert Message</title>
<script src=""></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')
$window.alert('Entered Name is : ' + $scope.username)
<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()" />

Live Demo

For live demo enter text in below textbox and click below button to see alert message

Enter Name :

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

Get the latest,, 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


Give your Valuable Comments

Other Related Posts

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