AngularJS $window Service Last Updated : 06 Sep, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report The $window service refers to the browser window object. It is globally available in JavaScript, so it causes testability problems. In AngularJS, it is not globally available. It includes various methods like alert box, prompt box, confirms box, etc. Now let us see the actual implementation of the $window service in Angular JS: $window.alert() Method: This method is used to display the alert message on the window screen. Example 1: This example describes the basic usage of the $window service in AngularJS by displaying the alert message. HTML <!DOCTYPE html> <html> <head> <title>$window service</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body ng-app="windowService"> <h2>Click on button to see the alert box</h2> <div ng-controller="windowServiceController"> <button ng-click="alertBox()"> Show Alert Box </button> </div> <script> var app = angular.module('windowService', []); app.controller('windowServiceController', ['$scope', '$window', function ($scope, $window) { $scope.message = "This is Alert Box"; $scope.alertBox = function () { $window.alert($scope.message); } }]); </script> </body> </html> Output: $window.prompt() Method: This method is used to display the prompt message on the screen.Example 2: This example describes the basic usage of the $window service in AngularJS by specifying the message in the prompt. HTML <!DOCTYPE html> <html> <head> <title>$window service</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body ng-app="windowService"> <h2>Click on button to see the Prompt box</h2> <div ng-controller="windowServiceController"> <button ng-click="promptBox()"> Show Prompt Box </button> <p>{{fullname}}</p> </div> <script> var app = angular.module('windowService', []); app.controller('windowServiceController', ['$scope', '$window', function ($scope, $window) { $scope.promptBox = function () { var name = $window.prompt('Enter Your Name'); $scope.fullname = 'Hello ' + name; } }]); </script> </body> </html> Output: $window.confirm() Method: This method is used to display a confirmation box on the screen.Example 3: This example describes the basic usage of the $window service in AngularJS by displaying the pop-up message for confirmation. HTML <!DOCTYPE html> <html> <head> <title>$window service</title> <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> </head> <body ng-app="windowService"> <h2>Click on button to see the Confirm box</h2> <div ng-controller="windowServiceController"> <button ng-click="confirmBox()"> Show Confirm Box </button> <p>{{confirmMessage}}</p> </div> <script> var app = angular.module('windowService', []); app.controller('windowServiceController', ['$scope', '$window', function ($scope, $window) { $scope.confirmBox = function () { var choice = $window.confirm("Are you sure ?") if (choice == true) $scope.confirmMessage = 'Welcome'; else $scope.confirmMessage = 'Sorry'; } }]); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article AngularJS $timeout Service J jimishravat2802 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Directives Similar Reads AngularJS $timeout Service Web development is a rapidly growing field. A technology introduced today is bound to get outdated within a few months. Earlier, the websites used to be static, with little to no animation or CSS. However, the introduction of vanilla JavaScript completely revolutionized the way websites used to look 3 min read Angular.js $log Service The $log service in Angular.js is simply used for logging purposes on the browser console. It is used for the debugging and troubleshooting of the error in the code. It has various implementations like a log, warn, info, error, and debugging, and all the names suggest. It is used for logging, warnin 5 min read AngularJS $document Service In AngularJS, a service is a function or object that is available for dependency injection (DI) in an AngularJS app. Services are typically used to encapsulate and reuse business logic and other app functionality that is not directly related to the presentation of data in the app. The $document serv 3 min read AngularJS $location Service The $location in AngularJS basically uses a window.location service. The $location is used to read or change the URL in the browser and it is used to reflect that URL on our page. Any change made in the URL is stored in the $location service in AngularJS. There are various methods in the $location s 4 min read AngularJS $interval Service The $interval service in AngularJS is a function that allows you to execute a function repeatedly at a specified interval. It is similar to the setInterval function in JavaScript, but it is designed to work seamlessly with the AngularJS framework. To use the $interval service, it is first needed to 4 min read AngularJS $controller Service AngularJS applications depend on a controller to control the flow of data through an AngularJS application. AngularJS architecture uses the MVC model i.e the Model View Controller. The model is responsible for maintaining the application data, the View for displaying data or some part of data to the 5 min read Like