title: Using $window or $location to Redirect in AngularJS
body: <p>The app I am working on contains various states (using ui-router), where some states require you to be logged in, others are publicly available.</p>
  <p>I have created a method that validly checks whether a user is logged in, what I am currently having issues with is actually redirecting to our login-page when necessary. It should be noted that the login page is not currently placed within the AngularJS app.</p>
  <pre><code>app.run(function ($rootScope, $location, $window) {
  
      $rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
  
          if (toState.data.loginReq &amp;&amp; !$rootScope.me.loggedIn) {
              var landingUrl = $window.location.host + &quot;/login&quot;;
              console.log(landingUrl);
              $window.open(landingUrl, &quot;_self&quot;);
          }
      });
  });
  </code></pre>
  <p>The console.log shows the intended URL properly. The line after that, I have tried practically everything from $window.open to window.location.href and no matter what I've tried no redirect happens.</p>