以下代码在使用$ http时正在运行,现在我用$ resource替换$ http并且我已经包含资源的依赖项和脚本但是我收到错误没有模块 - ngmodel。我哪里错了?
var x= angular.module('sampleApp',['ngResource'])
.factory("simpleFactory",function($resource){
var factory={};
factory.getStudents=function(){
return $resource("abc.json");
}
return factory;
})
.controller("ctrl1",function($scope,simpleFactory){
simpleFactory.getStudents().then(
function(result){
$scope.students=result.data;
})
})
答案 0 :(得分:1)
函数调用的结果是一个资源类对象,默认情况下有以下五种方法:
get()
query()
save()
remove()
delete()
修改工厂以调用以下方法:
.factory("simpleFactory",function($resource){
var factory={};
factory.getStudents=function(){
return $resource("abc.json").query();
}
return factory;
}) .controller("ctrl1",function($scope,simpleFactory){
$scope.students = simpleFactory.getStudents();
}