简体   繁体   English

错误:sessionStorage中的[$ injector:unpr]

[英]Error: [$injector:unpr] in sessionStorage

I am trying to store values from a form using sessionStorage. 我正在尝试使用sessionStorage从表单存储值。 But it is throwing error, 但这引发了错误,

Error: [$injector:unpr] http://errors.angularjs.org/1.2.25/$injector/unpr?p0=%24sessionStorageProvider%20%3C-%20%24sessionStorage 错误:[$ injector:unpr] http://errors.angularjs.org/1.2.25/$injector/unpr?p0=%24sessionStorageProvider%20%3C-%20%24sessionStorage

this is my app.js file 这是我的app.js文件

var BusRegModule = angular.module('BusRegModule', ['ui.router']);

BusRegModule.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
   $urlRouterProvider.otherwise('/');
    /* should route to sum.html(below code was used for checking) */
   $stateProvider.state('home', {      
           url: '/home',
           templateUrl: 'home.html'
   }); 
   $locationProvider.html5Mode(true);      
});

BusRegModule.controller('BusRegController',["$scope","$sessionStorage","$http", function($scope,$sessionStorage,$http){
 $scope.storage=$sessionStorage;
 $scope.businessReg=  {}
 $scope.submitMyForm=function() {        
     var q;
     sessionStorage.setItem("q",JSON.stringify($scope.businessReg));
     var d=sessionStorage.getItem("q"); 
     alert(d);
 };
}]);

And more doubt also, can anyone give me a simple example to do routing in angular js using $UrlRouterProvider. 还有更多的疑问,谁能给我一个简单的示例,使用$ UrlRouterProvider在angular js中进行路由。 I want to get values from a form(reg.html) using sessionStorage and need to route to an another page(sum.html) and echo out the values from form(reg.html) there. 我想使用sessionStorage从表单(reg.html)获取值,并且需要路由到另一个页面(sum.html)并在其中回显来自form(reg.html)的值。 The above code have lot of errors, any help would be life saving.. Thanks in advance. 上面的代码有很多错误,任何帮助都会挽救生命。.预先感谢。

Firstly along with the AngularJS JavaScript file, ngStorage.min.js file also needs to be inherited in order to perform operations on HTML5 LocalStorage and SessionStorage objects. 首先,除了AngularJS JavaScript文件之外,还需要继承ngStorage.min.js文件,以便对HTML5 LocalStorage和SessionStorage对象执行操作。 Then you need to pass ngStorage parameter in angular.module definition and then inject the $localStorage, $sessionStorage dependency in the controller. 然后,您需要在angular.module定义中传递ngStorage参数,然后将$ localStorage,$ sessionStorage依赖项注入控制器中。

Here is an example on how to save and get the data to and from the sessionStorage. 这是有关如何在sessionStorage中保存数据和从中获取数据的示例。 Here i have two functions 在这里我有两个功能

  1. to save data to sessionStorage 将数据保存到sessionStorage
  2. to get data 获取数据

     var app = angular.module('MyApp', ["ngStorage"]) app.controller('MyController', function ($scope, $localStorage, $sessionStorage, $window) { $scope.Save = function () { $sessionStorage.SessionMessage = "SessionStorage: Storing some data."; } $scope.Get = function () { $window.alert($sessionStorage.SessionMessage); } }); 

    I hope this helps :) 我希望这有帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM