您可以使用角度模拟来提供模拟后端.
plnkr工作演示.
基本上你在角度之后包括角度模拟,并使用this gist提供的代码
您将能够控制请求和响应,包括头文件和假响应延迟等.
例:
//When backend receives a request to the views folder,pass it through $httpBackend.whenGET( RegExp( regEsc( Config.view_dir ) ) ).passThrough(); //Message should return a list og messages $httpBackend.whenGET(APIBase + 'messages').respond(function(method,url,data,headers) { return [200,messages.data,{/*headers*/}]; }); $httpBackend.whenPOST(APIBase + 'messages').respond(function(method,headers) { var message = angular.fromJson(data); messages.data.push(message); //You should consider having the back-end being responsible for creating new id tho! messages.index[message.id] = message; return [200,message,{/*headers*/}]; }); //Message/id should return a message $httpBackend.whenGET( RegExp(regEsc(APIBase + 'messages') + '\d+$') ).respond(function(method,headers) { var id = url.match(/\d+$/)[0]; return [200,messages.index[id] || null,{/*headers*/}]; });
“`
您也可以设置要通过实际服务器的URL(检查passThrough())