[英]angular js Error: [$injector:unpr]
http://imgur.com/xTFVJTA是我的錯誤的圖片。
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();
};
}]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.