我正在尝试使用来自 mongolab 的 $resource 在 Angular 应用程序中显示数据。我在模块中添加了对 ngResource 的依赖。仍然显示未知提供者。这里缺少什么?
'$resource 未定义'
注意:当我的工厂名称不正确时,我收到错误:Unknown provider: employeesProvider <- employees
代码
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js"></script>
<script type="text/javascript">
//defining module
var app = angular.module('myApp', ['ngResource']);
//defining factory
app.factory('employees', function () {
return $resource('https://api.mlab.com/api/1/databases/humanresource/collections/Employees',
{apiKey: 'removedmykeyforpostinginSO'}
);
});
//defining controller
app.controller('myController', function ($scope, employees)
{
$scope.countries = employees.query();
});
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myController">
<ul>
<li ng-repeat = "objCountry in countries" >
{{objCountry.name}}
</li>
</ul>
</div>
</body>
</html>
来自蒙古实验室的 JSON
[ { "_id" : { "$oid" : "57044f95e4b0427faa38585f"} , "name" : "Lijo" , "age" : "30"} ]