Reputation: 4053
The code:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication3.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', ["$window"]);
app.controller('MyController', function ($scope, $window) {
$scope.Save = function () {
$window.sessionStorage.setItem("app1", "SessionStorage: My name is Mudassar Khan.");
}
$scope.Get = function () {
$window.alert("OK");
$window.alert($window.sessionStorage.getItem("app1"));
}
});
</script>
</head>
<body>
<div ng-app="MyApp" ng-controller="MyController">
<input type="button" value="Save" ng-click="Save()" />
<input type="button" value="Get" ng-click="Get()" />
</div>
</body>
</html>
It happens nothing.
Upvotes: 1
Views: 353
Reputation: 1891
When declaring your module, you have passed $window
as a dependency to it.
Angular sees it as an external module and tries to locate it, then you get this exception:
Module '$window' is not available!
$window
is not a module, it is an angular wrapper for window
object.
Try this:
var app = angular.module('MyApp', []);
Upvotes: 0
Reputation: 1849
The angular checks for window dependency and it fails. So remove it from module
and include only in controller
.
var app = angular.module('MyApp', []);
Upvotes: 1