嘲讽我使用的后端AngularJS [英] Mocking my backend using AngularJS

查看:149
本文介绍了嘲讽我使用的后端AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用REST / JSON调用获得/数据保存到数据库中的大量现有的SPA的应用程序。

I have a large existing SPA application which using REST/JSON calls to get/save data to the database.

我是最近推出AngularJS,我认为它真的很酷,尤其是它的嘲讽功能。

I was recently introduced to AngularJS and i think its really cool, especially its mocking feature.

不过,直到现在我没有完全理解我怎么能嘲笑后端调用终端到终端。

However, up until now i'm failing to grasp how can i mock a backend call end-to-end.

我正在寻找的是与HTML,控制器和模拟层向世人证明了如何在最简单的基本途径做一个简单的应用程序。我看见的jsfiddle的例子并没有真正做到这一点。

What I'm looking for is a simple application with the html, the controllers and the mock layer the demostrate how to do it with in the most simple basic way. The example that i saw on jsFiddle didn't really make it.

我把我的测试应用程序在线( http://plnkr.co/edit/HcaKeKqbHKZsvmuDt5tR )。正如你所看到的,这是一个是从角的网站,有轻微增加(复位PWD功能)。我想要做的就是添加一个模块,可以帮助我来测试复位PWD功能,通过截获JSONP调用(或任何其他JSON叫我在我的应用程序),相反,返回一个静态JSON数据对象。

i put my test app online (http://plnkr.co/edit/HcaKeKqbHKZsvmuDt5tR). As you can see, this is one is from Angular website, with minor addition (the reset pwd function). What i want to do is to add a module that can help me to test the reset pwd functionality, by intercepting the jsonp call (or any other json call the i have in my app), and instead, return a static json data object.

http://plnkr.co/edit/HcaKeKqbHKZsvmuDt5tR

任何人可以帮助我在这里?

Can anybody help me out here?

推荐答案

我认为你在寻找如何使用$ httpBackend服务。文档: http://docs.angularjs.org/api/ngMockE2E $ httpBackend和<一个HREF =htt​​p://docs.angularjs.org/api/ngMock​​相对=nofollow> http://docs.angularjs.org/api/ngMock 。$ httpBackend有相当大量的例子。

I think you're looking how to use $httpBackend service. Documentation: http://docs.angularjs.org/api/ngMockE2E.$httpBackend and http://docs.angularjs.org/api/ngMock.$httpBackend has quite lot examples.

我已经创建了样本嘲笑hackend Plunker例如:的http:// plnkr。 CO /编辑/ R4Bxs4u7n2iNjIMP0izh?p = preVIEW

I've created Plunker example with sample mocked hackend: http://plnkr.co/edit/R4Bxs4u7n2iNjIMP0izh?p=preview

嘲讽被完成的:

$httpBackend.whenGET('some.json').respond({name:"MyName"});

这篇关于嘲讽我使用的后端AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆