JSFiddle - React, Tailwind, and code Playground

Angular, calling an http twice only while passing different params.

by Andrew Pougher

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div ng-app="myApp">
  <form name="signup_form" ng-controller="PromiseCtrl" class="panel panel-default">
    <span class="badge">{{example1}}</span>
    <button class="btn btn-xs btn-info" ng-click="triggerJSONmaker()">
      Make it rain
    </button>
  </form>
</div>

JavaScript

var app = angular.module('myApp', []);
app.controller("PromiseCtrl", function($scope, $http, $timeout) {
  'use strict';

  $scope.makeJsonFiles = function(f) {
    var datacall = f || "one";

    $http.get('/echo/json').success(function(data, status, headers, config) {
      $scope.example1 = datacall;
    }).catch(function(data, status, headers, config) {
      alert("shit");
    }).finally(function() {
      $timeout(function() {
        $scope.makeJsonFiles('two')
      }, 1233);
      if (datacall == "two") $scope.example1 = "all done";
      return;
    })

  }

  $scope.triggerJSONmaker = function() {
    $scope.makeJsonFiles('one');
  }


});