进样器模块未捕获错误rr模块错误

时间:2018-11-18 11:35:27

标签: javascript jquery html angularjs angular-ui-router

未捕获的错误注入器模块rr模块错误。 角路由器无法正常工作。 在app.config中添加$ stateProvider之后,angulerjs会由于出现以下错误而停止工作。

Failed to instantiate module app due to: Error: [$injector:unpr] http://errors.angularjs.org/1.6.9/$injector/unpr?p0=%24st... at https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:7:76 at https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:46:64 at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:43:309) at e (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:44:39) at Object.invoke (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:44:124) at d (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:42:279) at https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:42:418 at r (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:8:7) at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:42:180) at gb (https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js:46:250

经过一些我不记得的更改之后,还会给出错误Error: $injector:unpr Unknown Provider Stateprovider

脚本

`angular.module('app',[])         “严格使用”;

   var app = angular.module('app').factory('AuthInterceptor', [function () {
        return {
            // Send the Authorization header with each request
            'request': function (config) {
                config.headers = config.headers || {};
                var encodedString = btoa("admin:admin");
                config.headers.Authorization = 'Basic ' + encodedString;
                return config;
            }
        };
    }]);


    app.config(['$httpProvider', '$stateProvider',function ($httpProvider, $stateProvider ) {
  $stateProvider
    .state('GradesData', {
      url: '/GradesData',
      templateUrl: '../GradesData.html'
    })
    .state('GradesForm', {
      url: '/GradesForm',
      templateUrl: '../GradesForm.html'
    })

  $httpProvider.interceptors.push('AuthInterceptor');

}]);`

包含以下脚本

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>

问题在添加 $ stateProvider 之后开始 添加了$ stateProvider,用于从angularjs页面和另一个angularjs页面上传递数据/值。

包括其他jquery脚本

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<script src="dist/js/adminlte.min.js"></script>
<script src="dist/js/demo.js"></script>

1 个答案:

答案 0 :(得分:0)

如果您使用的是<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>,请使用$routeProvider代替$stateProvider

然后您的代码将如下所示:

app.config(['$locationProvider', '$routeProvider',
      function($locationProvider, $routeProvider) {
        $locationProvider.hashPrefix('');
         $routeProvider
.when('/GradesData', {
         templateUrl: '../GradesData.html'})
.when('/GradesForm', {
         templateUrl: '../GradesForm.html'
            });
            $routeProvider.otherwise('/');
        }
    ]);

ngRoute添加到angular.module

angular.module('app', ['ngRoute'])

https://www.w3schools.com/angular/angular_routing.asp

对于$stateProvider,将ui.router添加到angular.module

angular.module('helloworld', ['ui.router']);

并使用

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/1.0.20/angular-ui-router.min.js"></script>

在此处查找:https://ui-router.github.io/ng1/tutorial/helloworld