谁能建议我如何模拟 $resource
对象
我已经通过互联网搜索过,但我所有的尝试都是通过 KARMA 测试完成的。 我不需要它。
我的想法是只使用假对象,这样我就可以在我的应用程序中的 $resource
实现之间切换。
谢谢。
最佳答案
您可以使用 $provide做这个。
angular.module(“MyApp”,[])
.config([“$provide”,function($provide){
$provide.decorator(“$resource”,function($delegate, myReplacementResource){
//$delegate is the original $resource, if you just want to modify it
//either inject a replacement resource that you have already registered
//as a factory (recommended). Or make it here.
return myReplacementResource;
});
}])
关于javascript - 模拟 Angular $resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24145775/