【发布时间】:2015-09-12 22:13:02
【问题描述】:
您好,我正在尝试使用 ngResource 从我的 api 获取 url,并且我有一个返回资源的服务。但是,当我在我的控制器中调用它时,会出现无法读取未定义的属性“查询”的错误。
为什么会这样?
这是我的服务:
(function() {
var app = angular.module('test');
app.service('ContactResource', ['$resource', function($resource) {
return $resource('/contacts/:firstname', {firstname: '@firstname'},
{
'update': {method: 'PUT'}
}
);
}]);
}());
这是我的控制器
(function() {
var app = angular.module('test');
app.controller('contactsCtrl', ['ContactResource', function($scope, Contacts, ContactResource) {
$scope.contacts = ContactResource.query();
}]);
}());
这是我的 HTML
<table class="table table-bordered">
<thead>
<th>Firstname <input type="search" class="pull-right"></th>
</thead>
<tbody>
<tr ng-repeat="contact in contacts">
<td>
<a ng-href="/{{ contact.firstname }}">{{ contact.firstname }}</a>
</td>
</tr>
</tbody>
</table>
【问题讨论】: