gpt4 book ai didi

javascript - 错误: [$injector:unpr] Unknown provider: $stateProvider?

转载 作者:行者123 更新时间:2023-12-03 06:45:19 27 4
gpt4 key购买 nike

我正在尝试使用 AngularJS 构建一个单页博客网站,但遇到了以下错误消息:

“未捕获错误:[$injector:modulerr] 无法实例化模块 spBlogger,原因是:错误:[$injector:modulerr] 无法实例化模块 spBlogger.posts,原因是:错误:[$injector:unpr] 未知提供者:$stateProvider"

尽管 $stateProvider 服务已经注入(inject),但我不确定为什么会发生这种情况。您能帮我确定为什么会收到此错误消息吗?

postModule.js 内容:

'use strict'

angular.module('spBlogger.posts', ['spBlogger.posts.controllers', 'spBlogger.posts.directives', 'spBlogger.posts.services', 'spBlogger.posts.filters']);

angular.module('spBlogger.posts')
.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) {
$stateProvider.state('allPosts', {
url: '/posts',
templateUrl: 'modules/posts/views/posts.html',
controller: 'PostController'
});
$stateProvider.state('singlePost', {
url: '/posts/:id/:permalink',
templateUrl: 'modules/posts/views/singlePost.html',
controller: 'PostDetailsController'
});
}]);

index.html内容:

<!doctype html>
<html lang="en" ng-app="spBlogger">

<head>
<meta charset="utf-8">
<base href="/">
<title>The Single Page Blogger</title>
<link rel="stylesheet" href="lib/bootstrap/bootstrap.min.css">
<link rel="stylesheet" href="css/app.css">
<link rel="stylesheet" href="modules/posts/css/posts.css">
</head>

<body>
<div class="container">
<br/>
<div class="jumbotron text-center">
<h1>The Single Page Blogger</h1>
<p>One stop blogging solution</p>
</div>
<div ui-view> The angular ui-view should be displayed here!</div>
<div class="row footer">
<div class="col-xs-12 text-center">
<p>The Single Page Blogger
<app-version/>
</p>
</div>
</div>
</div>
</body>
<!-- build:js app/built/app.min.js -->

<script src="lib/jquery/jquery.min.js"></script>
<script src="lib/bootstrap/bootstrap.min.js"></script>


<script src="lib/angular/angular.js"></script>
<script src="lib/angular-ui-router/angular-ui-router.min.js"></script>
<script src="lib/angular/angular-resource.js"></script>
<script src="lib/angular/angular-sanitize.js"></script>
<script src="lib/angular/angular-animate.js"></script>
<script src="lib/angular/angular-cookies.js"></script>

<script src="lib/angular/angular-translate.js"></script>

<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/directives.js"></script>
<script src="js/filters.js"></script>
<script src="js/services.js"></script>


<script src="modules/posts/postModule.js"></script>
<script src="modules/posts/js/controllers.js"></script>
<script src="modules/posts/js/filters.js"></script>
<script src="modules/posts/js/directives.js"></script>
<script src="modules/posts/js/services.js"></script>

<!-- endbuild -->

</html>

这是app.js

'use strict'

angular.module('spBlogger', ['ui.router', 'spBlogger.posts', 'spBlogger.controllers', 'spBlogger.directives', 'spBlogger.filters', 'spBlogger.services']);

angular.module('spBlogger').value('version', 'V1.0');


angular.module('spBlogger').run(['state', function (state) {
$state.go('allPosts');
}]);

Controller .js

'use strict'

angular.module('spBlogger.posts.controllers', [])


.controller('PostController', ['$scope', 'postService', function ($scope, postService) {
$scope.getAllPosts = function () {
return postService.getAll();
};
$scope.posts = $scope.getAllPosts();

}])


.controller('PostDetailsConstroller', ['$stateParams', '$state', '$scope', 'postService', function ($stateParams, $state, $scope, postService) {

$scope.getPostById = function (id) {
return postService.getPostById(id);
};


$scope.closePost = function () {
$state.go('allPosts');
};

$scope.singlePost = $scope.getPostById($stateParams.id);
}])


;

最佳答案

您错过了在应用程序模块中添加对 ui.router 的依赖项:

angular.module('spBlogger.posts', ['ui.router', 'spBlogger.posts.controllers', 'spBlogger.posts.directives', 'spBlogger.posts.services', 'spBlogger.posts.filters']);

Angular UI Router 不是 Angular 官方发行版的一部分,但它是由第三方开发团队开发的可选模块。

关于javascript - 错误: [$injector:unpr] Unknown provider: $stateProvider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37764301/

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