angular js Error: [$injector:unpr]
angular js Error: [$injector:unpr]
https://i.stack.imgur.com/u8QL3.jpg是我的错误图片。
dicym.js
var app = angular.module('diycm', ['ngRoute', 'LocalStorageModule']);
// setup the routing
app.config(function ($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'views/home.html',
controller: 'homeController',
title: 'Home'
})
.when('/projects', {
templateUrl: 'views/projects.html',
controller: 'homeController',
title: 'Projects'
})
.when('/singleProject', {
templateUrl: 'views/singleProject.html',
controller: 'homeController',
title: 'Project Details'
});
$routeProvider.otherwise({ redirectTo: "/home" });
});
// Controls the rootscope
app.run(function ($rootScope, $route) {
$rootScope.$on("$routeChangeSuccess", function (currentRoute, previousRoute) {
//Change page title, based on Route information
$rootScope.title = $route.current.title;
});
});
homeController.js
app.controller('homeController', function ($scope, $http) {
$scope.message = 'Everyone come and look!';
});
sidebarController.js
app.controller('sidebarController', function ($scope, $location) {
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
});
index.html
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.2/angular.min.js" type="text/javascript"></script>
<script src="https://code.angularjs.org/1.4.5/angular-route.js" type="text/javascript"></script>
<script src="js/diycm.js"></script>
<script src="js/angular-local-storage.min.js"></script>
<script src="js/controllers/sidebarController.js"></script>
<script src="js/controllers/homeController.js"></script>
有人知道是什么导致了这个错误吗?新的角度和文件/过去的问题没有太大帮助。
为每个控制器注入依赖项。
1)
app.controller('homeController', ['$scope','$http',function ($scope, $http) {
$scope.message = 'Everyone come and look!';
}]);
和
app.controller('sidebarController',['$scope','$location',function ($scope, $location) {
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
}]);
2)
app.controller('homeController',homeController);
homeController.$inject = ['$scope','$http'];
function homeController($scope, $http) {
$scope.message = 'Everyone come and look!';
}]);
和
app.controller('sidebarController',sidebarController);
sidebarController.$inject = ['$scope','$location'];
function sidebarController($scope, $location) {
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
}]);
相关文章:
- Angular $injector:unpr with uibModal
- 在出厂时注入服务错误: [$injector:unpr] 未知提供程序: $scopeProvider <- $scop
- AngularJS $UibModal triggering [$injector:unpr]
- AngularJS中的$injector.unpr错误
- angular.js:13424 Error: [$injector:unpr]
- angular js Error: [$injector:unpr]
- 错误: [$injector:unpr] 未知提供程序: setPageProvider <- setPage
- (IONIC)错误: [$injector:unpr] 未知提供程序: 数据服务提供程序 <- 数据服务<- 身份验证控
- 错误: [$injector:unpr] 未知提供程序 ->,因为 ui 路由器请求了错误的内容
- nggrid - 错误: [$injector:unpr] 未知提供程序: 网格服务提供程序 <- 网格服务<- 家庭控
- Angular Js $injector:unpr error
- angularjs + 下载 csv 文件 + 错误: [$injector:unpr] 未知提供程序
- Angularjs $injector:unpr 在缩小后的运行方法中
- 使用两种模式时出错:[$injector:unpr] 未知提供程序:$modalInstanceProvider <-
- 错误: [$injector:unpr] 未知提供程序: a.
- 实例化模块失败错误:[$injector:unpr]
- AngularJs Error - Uncaught Error: [$injector:unpr]
- 为什么我得到$injector:unpr(未知提供商)在这个单页应用程序
- Angularjs Error: $injector:unpr Unknown Provider with using
- 错误:[$injector:unpr]未知提供商:ngCsv <- ngCsv <- dynamicDemoContro