Angularjs Examples

AJS Examples

AngularJS $window Service

The AngularJS $window is similar to JavaScript window object. In angular it is refer to it through the $window service. In the JavaScript, window is a global object which includes many built-in methods like alert(), prompt() etc. The $window service in AngularJS is a wrapper around window object, so that it will be easy to override, remove or mocked for testing.


var name = $window.prompt('Enter Your Name');
$window.alert('Hello ' + name); 

AngularJS Identity Service Example

<!DOCTYPE html>
<head> <!-- -->
    <script src="//"></script>
    <meta charset="utf-8">
    <title>AngularJS $window Example</title>
var app = angular.module('app', []);
    app.controller("windowController", function ($scope, $window) {
      $scope.AngulerAlert = function (message) {
      $scope.AngulerPrompt = function () {
        var value = $window.prompt('Please enter value');
        $window.alert('Your Value : ' + value);
<body style="background-color:#DDE4E9;">
  <fieldset style="background-color:#DDE4E9;">            
    <legend>AngulerJS $window Service Example</legend> 
  <div ng-app="app">      
    <div ng-controller="windowController">      
        <button ng-click="AngulerAlert('Hello!!')">Alert Window</button>
    <button ng-click="AngulerPrompt()">Prompt Window</button>      
See Live Example