<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-httpbackend-e2e-testing-production</title>
<script src="//code.angularjs.org/snapshot/angular.min.js"></script>
<script src="//code.angularjs.org/snapshot/angular-mocks.js"></script>
<script src="app.js"></script>
<script src="e2e.js"></script>
</head>
<body ng-app="myAppE2E">
<div ng-controller="MainCtrl as $ctrl">
<form name="newPhoneForm" ng-submit="$ctrl.addPhone($ctrl.newPhone)">
<input type="text" ng-model="$ctrl.newPhone.name">
<input type="submit" value="Add Phone">
</form>
<h1>Phones</h1>
<ul>
<li ng-repeat="phone in $ctrl.phones">{{phone.name}}</li>
</ul>
</div>
</body>
</html>
<!--
Copyright 2017 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
-->
(function(angular) {
'use strict';
var myApp = angular.module('myApp', []);
myApp.controller('MainCtrl', function MainCtrl($http) {
var ctrl = this;
ctrl.phones = [];
ctrl.newPhone = {
name: ''
};
ctrl.getPhones = function() {
$http.get('/phones').then(function(response) {
ctrl.phones = response.data;
});
};
ctrl.addPhone = function(phone) {
$http.post('/phones', phone).then(function() {
ctrl.newPhone = {name: ''};
return ctrl.getPhones();
});
};
ctrl.getPhones();
});
})(window.angular);
/*
Copyright 2017 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/
(function(angular) {
'use strict';
var myAppDev = angular.module('myAppE2E', ['myApp', 'ngMockE2E']);
myAppDev.run(function($httpBackend) {
var phones = [{name: 'phone1'}, {name: 'phone2'}];
// returns the current list of phones
$httpBackend.whenGET('/phones').respond(phones);
// adds a new phone to the phones array
$httpBackend.whenPOST('/phones').respond(function(method, url, data) {
var phone = angular.fromJson(data);
phones.push(phone);
return [200, phone, {}];
});
});
})(window.angular);
/*
Copyright 2017 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license
*/