有人实现过类似 ember fixture adapter 的东西吗?在 AngularJS 中用于在开发过程中模拟后端?
我看到 AngularJS 有 $httpBackend用于进行单元测试,但是可以像 ember 固定适配器一样使用它来运行实际应用程序吗?
如果当前没有任何可用的东西,如何以允许固定装置和实际后端(针对开发和生产环境)之间轻松转换的方式实现?
最佳答案
我个人更喜欢使用mockjax(https://github.com/appendto/jquery-mockjax)。
$.mockjax({
url: '/colors',
dataType: 'json',
responseText: {
colors:[
{
id: 1,
color: "red"
},
{
id: 2,
color: "green"
},
{
id: 3,
color: "blue"
}
]
}
});
这是一个 ember 示例,但它在 Angular 中的工作原理完全相同。
关于javascript - AngularJS 中 Ember 夹具适配器的等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23959733/