cou*_*011 2 angularjs angular-resource
这是我的js代码
var MYModule = angular.module('myApp', ['ngRoute', 'myAppServices'])
.directive('loading', ['$http', loadingDirective])
.config(myRouter);
angular.module('myAppServices', ['ngResource'])
.factory('Users', function($resource) {
return $resource('/MY/system/users');
});
function UsersCtrl($scope, Users) {
$scope.users = Users.query();
}
Run Code Online (Sandbox Code Playgroud)
在我的HTML代码中使用这个
<div ng-repeat="item in users">Hello</div>
Run Code Online (Sandbox Code Playgroud)
虽然我在/ MY/system/users的服务器代码中收到请求,但是浏览器出错了
Error: [$resource:badcfg] http://errors.angularjs.org/1.2.16/$resource/badcfg?p0=array&p1=object
at Error (native)
Run Code Online (Sandbox Code Playgroud)
请参阅此错误文档:https://docs.angularjs.org/error/$resource/badcfg
当角度期望阵列或对象,并且接收相反时,会发生这种情况.query()期望从您的端点返回一个数组,同时get()期望一个对象.
此外,您应该将query()上面的语法更改为:
Users.query().then(function(result){
$scope.users = result;
});
Run Code Online (Sandbox Code Playgroud)
这是因为角度正在逐步淘汰通过返回的承诺的自动处理$http.
| 归档时间: |
|
| 查看次数: |
3131 次 |
| 最近记录: |