JSFiddle - React, Tailwind, and code Playground

by Pankaj Parkar

HTML

<div ng-app='myApp'>
  <div ng-controller="myCtrl">
    <button ng-click="open()">Open</button>
    <br>
    <button ng-click="focus()">Focus</button>
    <br>
  </div>
</div>

JavaScript

var myApp = angular.module('myApp', []);
myApp.controller('myCtrl', function($scope, $window, $http) {
  var that = this;
  $scope.open = function() {
    that.myWin = $window.open('http://www.google.com', '_blank');
  };

  $scope.focus = function() {
    var promiseResolved = false;
    $http.get('').then(function() {
      promiseResolved = true;
      console.log("I'm here");
    });
    var interval = setInterval(function() {
      if (promiseResolved) {
				that.myWin.focus();
				clearInterval(interval);  
      }
    }, 500);
  };
});