首页 > 解决方案 > 我的控制台中的 Angularjs $injector:unpr 错误

问题描述

我收到 angularjs $injector.unpr 错误。我试图检查拼写,但一切都是正确的。

Error: [$injector:unpr] http://errors.angularjs.org/1.7.2/$injector/unpr?p0=%24routeParamsProvider%20%3C-%20%24routeParams%20%3C-%20searchResultsController
    at angular.js:99
    at angular.js:4891
    at Object.d [as get] (angular.js:5051)
    at angular.js:4896
    at d (angular.js:5051)
    at e (angular.js:5076)
    at Object.instantiate (angular.js:5120)
    at angular.js:11175
    at Object.<anonymous> (angular-ui-router.min.js:7)
    at angular.js:1364 "<div class="well ng-scope" ui-view="">"

header.html 上的标题搜索框

  <form ng-submit="search()">
            <input type="text" class="form-control" placeholder="Search term" ng-model="query" style="width:20%">
            <button type="submit" class="btn btn-default">Search</button>
        </form>

headercontroller.js

(function () {
    'use strict';

    var app = angular.module('myApp');
    app.controller("headerController", headerController);

    headerController.$inject = ['$scope', '$http', '$rootScope', '$routeParams', '$location', '$q'];

    function headerController($scope, $http, $rootScope, $routeParams, $location, $q) {
        var vm = this;

 $scope.search = function () {
                $location.path('searchIndex').search({ query: $scope.query });
            };
    }
})();

searchResultsController.js

(function () {
    'use strict';

    var app = angular.module('myApp');
    app.controller("searchResultsController", searchResultsController);

    searchResultsController.$inject = ['$scope', '$http', '$rootScope', '$routeParams', '$location', '$q'];

    function searchResultsController($scope, $http, $rootScope, $routeParams, $location, $q) {
        var vm = this;

        $scope.query = $routeParams.query;
        $scope.url = $location.absUrl();
    }
})();

应用程序.js

.state('searchIndex', {
                    url: "/searchIndex",
                    templateUrl: "SOC/Views/Search/index.html",
                    controller: "searchResultsController"
                })

搜索结果 index.html

<h2>Search results</h2>
<p>Query: {{query}}</p>
<p>URL: {{url}}</p>
<br>
<p>Use <code>$scope.query</code> to make a search request and display results.</p>

我是否缺少任何解决此错误的方法

标签: angularjs

解决方案


推荐阅读