Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
  <script src="https://rawgit.com/okiss/0f704bc99bb2359e07d0/raw/80332f9257b9dad4bb92270461cc9cf1c2b7b880/angular-resource-pr12525.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="app" ng-controller="AppController as ctrl">
  <button ng-click="ctrl.request()">create request</button>
  <button ng-click="ctrl.cancel()">cancel request</button>
  {{ctrl.response}}
</body>
</html>
 
var app = angular.module('app', ['ngResource']);
app.controller('AppController', function ($resource, $q, $log) {
  var vm = this,
      canceller = $q.defer();
  
  vm.request = function () {
    $log.info('requesting');
    this.response = null;
    $resource(
      'http://pivohled.cz',
      {},
      {
        query: {
          method: 'GET',
          isArray: false,
          timeout: canceller.promise
        }
      }
    ).query().$promise.then(function (data) {
      $log.info('response: ' + data.message);
      vm.response = data.message;
    }).catch(function (error) {
      $log.info('cancelled: ' + error.status);
      vm.response = 'request was cancelled';
    });
  };
  
  vm.cancel = function () {
    $log.info('cancelling');
    canceller.resolve();
    canceller = $q.defer();
  };
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers