javascript - 模块 'ngStorage' 不可用

标签 javascript angularjs module

所以,我是 Angular 的新手,我正在构建一个将数据保存在浏览器的 localStorage 中的应用程序。我正在尝试为此使用 ngStorage,但出现以下错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due      to:
Error: [$injector:modulerr] Failed to instantiate module myApp.funcionarios due to:
Error: [$injector:modulerr] Failed to instantiate module ngStorage due to:
Error: [$injector:nomod] Module 'ngStorage' is not available! You either     misspelled the module name or forgot to load it. If registering a module ensure     that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.5.11/$injector/nomod?p0=ngStorage
at http://localhost:8000/bower_components/angular/angular.js:68:12
at http://localhost:8000/bower_components/angular/angular.js:2133:17
at ensure     (http://localhost:8000/bower_components/angular/angular.js:2057:38)
at module (http://localhost:8000/bower_components/angular/angular.js:2131:14)
at http://localhost:8000/bower_components/angular/angular.js:4669:22
at forEach (http://localhost:8000/bower_components/angular/angular.js:325:20)
at loadModules (http://localhost:8000/bower_components/angular/angular.js:4653:5)
at http://localhost:8000/bower_components/angular/angular.js:4670:40
at forEach (http://localhost:8000/bower_components/angular/angular.js:325:20)
at loadModules     (http://localhost:8000/bower_components/angular/angular.js:4653:5)

http://errors.angularjs.org/1.5.11/ $注入(inject)器/模块?

我已经阅读了很多论坛,并且已经研究了所有我能找到的答案,但仍然没有运气。任何人都可以看到我遗漏的东西吗?

这是我的索引脚本:

<script src="bower_components/ngstorage/ngStorage.js"></script>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="components/version/version.js"></script>
<script src="components/version/version-directive.js"></script>
<script src="components/version/interpolate-filter.js"></script>
<script src="funcionarios/funcionarios.js"></script>
<script src="app.js"></script>

我的 app.js:

'use strict';

// Declare app level module which depends on views, and components
angular.module('myApp', ['myApp.funcionarios', 'ngRoute', 'ngStorage' ])

.config(['$locationProvider', '$routeProvider', function($locationProvider,     $routeProvider) {
$locationProvider.hashPrefix('!');

  $routeProvider.otherwise({redirectTo: '/funcionarios'});
}]);

这是 myApp.funcionarios:

'use strict';

angular.module('myApp.funcionarios', ['ngRoute', 'ngStorage'])
    .config(['$routeProvider', function($routeProvider) {
        $routeProvider.when('/funcionarios', {
            templateUrl: 'funcionarios/funcionarios.html',
            controller: 'FuncionariosCtrl'
        });
    }])

      .controller('FuncionariosCtrl', ['$scope', '$localStorage',     '$sessionStorage', function( $scope, $localStorage, $sessionStorage ) {

非常感谢任何帮助!谢谢

最佳答案

只需将您的 ng-storage 脚本标签移动到 angular 下方。这取决于 Angular ,所以它应该在那之后:

<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/ngstorage/ngStorage.js"></script>    
<script src="components/version/version.js"></script>
<script src="components/version/version-directive.js"></script>
<script src="components/version/interpolate-filter.js"></script>
<script src="funcionarios/funcionarios.js"></script>
<script src="app.js"></script>

关于javascript - 模块 'ngStorage' 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42284938/

相关文章:

javascript - getRowHeight() 不适用于 rowModelType = 'infinite' 和最新的 ag-grid 版本

javascript - 私有(private)预渲染服务器不会渲染 angularjs 脚本?

mysql - Nodejs mysql 模块返回记录两次而不是一次

javascript - Angular js 设置在没有 $scope 的情况下使用 $on

python - "library"方法的范围

java - 使用 OpenJDK 14 java 模块运行时时 TLS 1.3 握手失败

javascript - 如何使用 jQuery/javascript 构建关联数组?

javascript - "this"函数中 对象中 函数中

javascript - 无法手动设置 slider

javascript - 如何加载嵌套 3 种状态深度的 UI-router ui-view 模板?