Error: [$injector:unpr] in AngularJS
Error: [$injector:unpr] in AngularJS
我正在从事 webApi 项目。我想在我的数据库中列出学生。当我在不使用服务(工厂)的情况下执行此操作时,它会起作用。但是当我创建服务时它不起作用并且出现错误。我知道这个网站也有同样的问题。但答案没有用,所以我问。这是我的文件;
studentServis.js:
(function () {
'use strict';
angular
.module('studentApp')
.factory('studentService', [
"$http","studentApiUrl",
function ( $http,studentApiUrl) {
var getAll = function () {
return $http.get(studentApiUrl);
};
var service = {
getAll: getAll
};
return service;
}
]);
})();
studentController.js:
(function () {
'use strict';
angular
.module('studentApp')
.controller('studentController', [
"$scope", "studentService",
function ($scope, studentService) {
$scope.message = "hey";
studentService.getAll().then(function (data) {
$scope.students = data;
});
}
]); })();
studentApp.js:
(function () {
'use strict';
var app=angular.module('studentApp', [
// Angular modules
'ngRoute'
]).constant('studentApiUrl', "/api/student/"); })();
Index.html:
<div ng-app="studentApp">
<div ng-controller="studentController">
{{message}}
<table class="table table-bordered">
<tbody>
<tr ng-repeat="student in students">
<td>{{student.id}}</td>
<td>{{student.firstname}}</td>
<td>{{student.lastname}}</td>
<td>{{student.university}}</td>
<td>
<a href="#/details/{{student.id}}" class="btn btn-default btn-sm">Edit</a>
<button class="btn btn-danger btn-sm" ng-click="delete(student)">Delete</button> -->
</td>
</tr>
</tbody>
</table>
</div>
</div>
$scope.message
(嘿)部分仅供尝试。它也不打印它。输出在网站中:
{{message}}
我的学生名单什么都没有。
这里是错误:
angular.js:15018 Error: [$injector:unpr]
at angular.js:99
at angular.js:4891
at Object.d [as get] (angular.js:5051)
at angular.js:4896
at d (angular.js:5051)
at e (angular.js:5076)
at Object.invoke (angular.js:5100)
at P.instance (angular.js:11160)
at p (angular.js:10031)
at g (angular.js:9370)
我看了这里,但我认为我在那里说的是对的:AngularJS Error Reference - $injector unpr
这里是索引中的引用:
<head>
<meta charset="utf-8" />
<title></title>
<script src="../../Scripts/angular.min.js"></script>
<script src="../../Scripts/angular.js"></script>
<script src="../../Scripts/angular-route.js"></script>
<script src="../Scripts/studentApp.js"></script>
<script src="../Scripts/studentServis.js"></script>
<script src="../Scripts/studentController.js"></script>
<link href="../../Content/Site.css" rel="stylesheet" />
<link href="../../Content/bootstrap.css" rel="stylesheet" />
好的,有没有人可以帮助我?
我没有看到你在任何地方加载你的服务,顺序应该是,
<script src="../Scripts/studentApp.js"></script>
<script src="../Scripts/studentServis.js"></script>
<script src="../Scripts/studentController.js"></script>
我正在从事 webApi 项目。我想在我的数据库中列出学生。当我在不使用服务(工厂)的情况下执行此操作时,它会起作用。但是当我创建服务时它不起作用并且出现错误。我知道这个网站也有同样的问题。但答案没有用,所以我问。这是我的文件;
studentServis.js:
(function () {
'use strict';
angular
.module('studentApp')
.factory('studentService', [
"$http","studentApiUrl",
function ( $http,studentApiUrl) {
var getAll = function () {
return $http.get(studentApiUrl);
};
var service = {
getAll: getAll
};
return service;
}
]);
})();
studentController.js:
(function () {
'use strict';
angular
.module('studentApp')
.controller('studentController', [
"$scope", "studentService",
function ($scope, studentService) {
$scope.message = "hey";
studentService.getAll().then(function (data) {
$scope.students = data;
});
}
]); })();
studentApp.js:
(function () {
'use strict';
var app=angular.module('studentApp', [
// Angular modules
'ngRoute'
]).constant('studentApiUrl', "/api/student/"); })();
Index.html:
<div ng-app="studentApp">
<div ng-controller="studentController">
{{message}}
<table class="table table-bordered">
<tbody>
<tr ng-repeat="student in students">
<td>{{student.id}}</td>
<td>{{student.firstname}}</td>
<td>{{student.lastname}}</td>
<td>{{student.university}}</td>
<td>
<a href="#/details/{{student.id}}" class="btn btn-default btn-sm">Edit</a>
<button class="btn btn-danger btn-sm" ng-click="delete(student)">Delete</button> -->
</td>
</tr>
</tbody>
</table>
</div>
</div>
$scope.message
(嘿)部分仅供尝试。它也不打印它。输出在网站中:
{{message}}
我的学生名单什么都没有。
这里是错误:
angular.js:15018 Error: [$injector:unpr] at angular.js:99 at angular.js:4891 at Object.d [as get] (angular.js:5051) at angular.js:4896 at d (angular.js:5051) at e (angular.js:5076) at Object.invoke (angular.js:5100) at P.instance (angular.js:11160) at p (angular.js:10031) at g (angular.js:9370)
我看了这里,但我认为我在那里说的是对的:AngularJS Error Reference - $injector unpr
这里是索引中的引用:
<head>
<meta charset="utf-8" />
<title></title>
<script src="../../Scripts/angular.min.js"></script>
<script src="../../Scripts/angular.js"></script>
<script src="../../Scripts/angular-route.js"></script>
<script src="../Scripts/studentApp.js"></script>
<script src="../Scripts/studentServis.js"></script>
<script src="../Scripts/studentController.js"></script>
<link href="../../Content/Site.css" rel="stylesheet" />
<link href="../../Content/bootstrap.css" rel="stylesheet" />
好的,有没有人可以帮助我?
我没有看到你在任何地方加载你的服务,顺序应该是,
<script src="../Scripts/studentApp.js"></script>
<script src="../Scripts/studentServis.js"></script>
<script src="../Scripts/studentController.js"></script>