Html 错误:$injector:unpr未知提供程序:SampleDataProvider
我很难理解在将json数据导入到我的应用程序时我做错了什么。我在控制台工具中没有看到任何get调用,并且我一直收到$injector:unpr错误。我已经在controller.js中编写了这段代码Html 错误:$injector:unpr未知提供程序:SampleDataProvider,html,angularjs,Html,Angularjs,我很难理解在将json数据导入到我的应用程序时我做错了什么。我在控制台工具中没有看到任何get调用,并且我一直收到$injector:unpr错误。我已经在controller.js中编写了这段代码 function caderror($scope, SampleData) { // Run method getFullList() from factory SampleData.getFullList().success(function(data){
function caderror($scope, SampleData) {
// Run method getFullList() from factory
SampleData.getFullList().success(function(data){
// Assign data to $scope
$scope.dataFromFactory = data;
});
}
这里是factories.js,这里引用了示例数据
function SampleData($http) {
// Return the object
return {
// Create simple method to get data from $http service
getFullList : function() {
return $http({
url: 'http://somewebsite/api/example.json',
method: 'GET'
})
}
}
}
angular
.module('inspinia')
.factory('SampleData', SampleData);
下面是我用来将JSON数据调用到表中的HTML
<div class="row wrapper border-bottom white-bg page-heading">
<div class="col-lg-10">
<h2>CAD Error Logs</h2>
<ol class="breadcrumb">
<li>
<a href="index.html">Home</a>
</li>
<li>
<a>Tables</a>
</li>
<li class="active">
<strong>Data Tables</strong>
</li>
</ol>
</div>
<div class="col-lg-2">
</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-12">
<div class="text-center m-t-lg">
<h1>
Simple factory to get data from server
</h1>
</div>
</div>
<div class="col-lg-6 col-lg-offset-3">
<div class="ibox">
<div class="ibox-content">
<p class="text-center">
Table with data from api/example.json
</p>
<table class="table table-striped">
<thead>
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
Company
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in dataFromFactory">
<td>
{{item.id}}
</td>
<td>
{{item.name}}
</td>
<td>
{{item.company}}
</td>
<td>
{{item.desc}}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
我做错了什么,如果需要更多的代码,请让我知道,我会发布它。我读到这个错误,它说它是由于无法解决所需的依赖关系而导致的。我将如何着手解决这个问题。angular js的错误站点并没有真正帮助我
编辑
这是错误消息
错误:[$injector:unpr]aderror
我可以显示其余部分,但它们只是angular.min.js中的文件行此错误通常是由于引用出现问题而发生的 错误告诉我们函数caderror正在查找SampleData,但找不到它。当包含SampleData代码的文件未包含在引用中,或者在需要它的文件(在本例中是包含caderror的文件)之后列出时,最常发生这种情况
你也应该考虑不要使用,因为你的方法已经被贬低了。请参阅角标记,用于角2 +,这看起来像盎格鲁JS——旧版本,也应该考虑不使用。我指的是JSON文件,而不是JSON文件;您在此处称为factories.js的文件;在HTML中的何处是,以及在此之前和之后加载了哪些其他脚本?函数caderror正在查找SampleData,但找不到它,这通常意味着SampleData的代码未包含脚本缺失或脚本顺序错误。