JSFiddle - React, Tailwind, and code Playground

by chandings

HTML

<script src="http://code.angularjs.org/angular-1.0.0.js"></script>
<div ng-app="myApp" ng-controller="myController">
    <button ng-click="clickHandler1()">button 1</button>
    <button ng-click="clickHandler2()">button 2</button>
</div>

JavaScript

var myApp = angular.module('myApp', []);
myApp.controller("myController", ["$scope", "myService", function (scope, myService) {
    scope.clickHandler1 = function () {
        var promise = myService.getRealData();
        promise.then(function (data) {
            alert("success: " + data)
        }, function (error) {
            alert("failure: " + error)
        }, function (message) {
            alert("notification: " + message)
        });
    };

    scope.clickHandler2 = function () {
        var promise = myService.getNoData();
        promise.then(function (data) {
            alert("success: " + data)
        }, function (error) {
            alert("failure: " + error)
        }, function (message) {
            alert("notification: " + message)
        });
    }
}]);
myApp.factory("myService", ['httpWithRetries', function (http) {
    return {
        getRealData: function () {
            return http.send({
                method: 'POST',
                data: 'Its Working',
                url: '/echo/html/'
            });
        },
        getNoData: function () {
            return http.send({
                method: 'POST',
                data: 'Its Working',
                url: 'http://example.com/dummy'
            });
        }
    }
}]);
myApp.provider("httpWithRetries", function () {
    var retries = 3;
    var interval = 1000;
    this.$get = ["$http", "$q", "$timeout", function (http, q, timeout) {
        var returnObject = {};
        returnObject.tryCount = 0;
        returnObject.send = function (data) {
            console.log(this.tryCount);
            var currObject = this;
            var deferred = q.defer();
            console.log("httpWithRetry url: " + data.url);
            http(data)
                .success(function (result) {
                console.log("httpWithRetry success");
                console.log("httpWithRetry result: " + result);

                deferred.resolve(result);
            })
               ...