gpt4 book ai didi

javascript - 获取 [$injector :unpr] error using Angular. js

转载 作者:行者123 更新时间:2023-12-02 14:13:38 25 4
gpt4 key购买 nike

使用 Angular.js 单击链接时出现以下错误。

错误:

VM1186 angularjs.js:107 Error: [$injector:unpr] http://errors.angularjs.org/1.4.6/$injector/unpr?p0=UploadProvider%20%3C-%20Upload%20%3C-%20adminCatCategoryController
at Error (native)
at https://run.plnkr.co/8hsX4IhGSoTXwnkj/angularjs.js:6:416
at https://run.plnkr.co/8hsX4IhGSoTXwnkj/angularjs.js:40:409
at Object.d [as get] (https://run.plnkr.co/8hsX4IhGSoTXwnkj/angularjs.js:38:394)
at https://run.plnkr.co/8hsX4IhGSoTXwnkj/angularjs.js:40:483
at d (https://run.plnkr.co/8hsX4IhGSoTXwnkj/angularjs.js:38:394)
at e (https://run.plnkr.co/8hsX4IhGSoTXwnkj/angularjs.js:39:161)
at Object.instantiate (https://run.plnkr.co/8hsX4IhGSoTXwnkj/angularjs.js:39:310)

我的代码如下。

index.html:

<html ng-app="Spesh">

<head>
<link data-require="bootstrap@*" data-semver="4.0.0-alpha.2" rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css" />
<script data-require="bootstrap@*" data-semver="4.0.0-alpha.2" src="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/js/bootstrap.js"></script>
<script data-require="jquery@*" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
<script src="angularjs.js" type="text/javascript"></script>
<script src="angularuirouter.js" type="text/javascript"></script>
<script src="angularuibootstrap.js" type="text/javascript"></script>
<script src="loginRoute.js" type="text/javascript"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>

<body>
<h1>Test tab</h1>
<div ui-view></div>
<script src="adminController.js" type="text/javascript"></script>
<script src="adminCategoryController.js" type="text/javascript"></script>
<script src="adminCatCategoryController.js" type="text/javascript"></script>
<script src="adminSubcatCategoryController.js" type="text/javascript"></script>
</body>

</html>

loginRoute.js:

var Admin = angular.module('Spesh', ['ui.router','ui.bootstrap']);
Admin.run(function($rootScope, $state) {
$rootScope.$state = $state;
});
Admin.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise('/');
$stateProvider
.state('/', {
url: '/',
templateUrl: 'dashboard.html',
controller: 'adminController'
})
.state('category', { /* This state defines the department management page */
url: '/category',
templateUrl: 'category.html',
controller: 'adminCategoryController'
})

.state('category.cat', { /* This state defines the department management page */
url: '/manage_category',
templateUrl: 'manage_category.html',
controller: 'adminCatCategoryController'
})

.state('category.subcat', { /* This state defines the department management page */
url: '/manage_subcategory',
templateUrl: 'manage_subcategory.html',
controller: 'adminSubcatCategoryController'
})
})

仪表板.html:

<nav>
<ul>
<li ng-class="{'active open': $state.includes('category')}"><a ui-sref="category.cat">Category</a></li>
</ul>
</nav>

<div class="row" style="padding-top:120px;" ui-view>

</div>

当我点击Category链接时,出现上述错误。我的Plunkr code is here 。如何解决此错误?

最佳答案

在您的 plunker 中,链接“category/manage_category”将使用“adminCatCategoryController” Controller 。它有一些代码:

dashboard.controller('adminCatCategoryController',function($scope,$http,$location,$window,$state,上传,focusInputField){
})

我找不到任何将“Upload”、“focusInputField”定义为service/factory或constant的文件。所以当你在这里注入(inject)它们时,Angular 无法检测到它们并抛出错误。

删除或定义它们将解决您的问题。

希望对您有帮助!谢谢!

关于javascript - 获取 [$injector :unpr] error using Angular. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39247546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com