Javascript 角度js错误:[$injector:unpr]
这是我错误的写照 dicym.jsJavascript 角度js错误:[$injector:unpr],javascript,angularjs,Javascript,Angularjs,这是我错误的写照 dicym.js var app = angular.module('diycm', ['ngRoute', 'LocalStorageModule']); // setup the routing app.config(function ($routeProvider) { $routeProvider .when('/home', { templateUrl: 'views/home.html', controller:
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!';
});
app.controller('sidebarController', function ($scope, $location) {
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
});
sidebarController.js
app.controller('homeController', function ($scope, $http) {
$scope.message = 'Everyone come and look!';
});
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>
有人知道是什么导致了这个错误吗?angular的新手和文档/过去的问题没有多大帮助。为每个控制器注入依赖项 (一) 及 2)
和
app.controller('sidebarController',sidebarController);
sidebarController.$inject = ['$scope','$location'];
function sidebarController($scope, $location) {
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
}]);
为每个控制器注入依赖项 (一) 及 2)
和
app.controller('sidebarController',sidebarController);
sidebarController.$inject = ['$scope','$location'];
function sidebarController($scope, $location) {
$scope.isActive = function (viewLocation) {
return viewLocation === $location.path();
};
}]);
您没有在控制器中注入依赖项。您应该注入依赖项,然后再次运行代码。您没有在控制器中注入依赖项。您应该注入依赖项,然后再次运行代码。