title: It is safe to use $window.location.assign instead of $location.path()? | angularjs
body: <p>I'm writing a service in AngularJS and I want that service do a redirection on a page I choose. I don't have a $scope in this so I'm using:</p>
  
  <pre><code>$window.location.assign('path');
  </code></pre>
  
  <p>as <a href="http://www.w3schools.com/js/js_window_location.asp" rel="nofollow">documented on w3c</a>.</p>
  
  <p>What I'm asking is if this is a safe usage or if I should use something different.</p>
  
  <p>ps: those doesn't work:</p>
  
  <pre><code>$location.assign(); //assign is not a function
  //
  $location.path();
  $scope.$apply(); //I don't have a $scope
  </code></pre>
  
  <p>Many thanks.</p>
  
  <p><strong>EDIT:</strong> added code (in <code>socketio.listen('auth.loggedInSuccessfully', function(data) {</code> I'm having the issue I described)</p>
  
  <pre><code>angular.module('frontendApp')
      .factory('login', function ($window, socketio, $rootScope) {
          // Service logic
          // ...
          var loginType = null;
  
          // prepare socketio events
          socketio.listen();
  
          socketio.listen('auth.loggedInSuccessfully', function(data) {
              console.log("Login verified by server!.. Redirecting...");
              console.log("Login data received: " + JSON.stringify(data));
              $rootScope.user = data.user;
              $rootScope.$apply();
              loginType = "facebook";
              //console.log("$rootScope.user: " + JSON.stringify($rootScope.user.name));
              //$location.path(destUrl); // THIS doesn't work.
              $window.location.assign(data.destUrl); // this does!
          });
          socketio.listen('auth.loginFailed', function() {
              console.log("Login failed!");
              $rootScope.user = {}
          });
          socketio.listen('auth.logout', function() {
              console.log("Logged out!");
              $rootScope.user = {};
          })
  
          // Public API here
          var api = {
              fb: {
                  validateToken: function (access_token, destUrl) {
                      socketio.emit('fb.login', {
                          access_token: access_token,
                          destUrl: destUrl
                      });
                      console.log("Waiting server response...");
                  },[...]
          };
          return api;
      });
  </code></pre>