Search code examples
angularjsangularjs-routingui-sref

ui-sref redirect to a url with a different port


I have the following code in my template:

 <a class="menu-button" id="addBtn" ui-sref="board" />

And the home.js entry for the board state is the following:

.state('board', {
    url: 'http://' + $location.host() + ':11002/goToBoard'
})

However, the redirect is not done properly, because the port part is not considered at all. I also tried giving the entire path, but that failed too.

Any thoughts?


Solution

  • it doesn't make sense to redirect to a url with a different port using ui-sref, because it is completely a different website. just use

     <a href="http://localhostorwhatever.com:11002/goToBoard"></a>
    

    to get hostname dynamically you could use ng-href

    <a ng-href="http://{{getCurrentLocation()}}:11002/goToBoard"></a>
    
    $scope.getCurrentLocation = function(){return $location.host()};
    

    you need to inject $location service to your controller for this