var app = angular.module('myApp', []);
// we want to use $httpBackend mock
app.config(function($provide) {
$provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);
});
// define our fake backend
app.run(function($httpBackend) {
// do not bother server, respond with given content
$httpBackend.whenGET('template1.html').respond(200, 'just some content', {header: 'one'});
// you can specify only content, it will respond with 200 status code
$httpBackend.whenGET('template2.html').respond('Another content');
// do real request
$httpBackend.whenJSONP().passThrough();
});
// a controller
function Main($http) {
this.current = 0;
this.template = ['template1.html', 'template2.html'];
this.switchTpl = function() {
this.current = (this.current + 1) % this.template.length;
};
this.loadPassword = function() {
this.promise = $http.jsonp('http://angularjs.org/generatePassword.php?callback=JSON_CALLBACK');
};
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.