How to open new tab in browser by using $location, angular?

后端 未结 4 2023
太阳男子
太阳男子 2021-02-11 21:56

I have controller \'reportCtrl\' and HTML that represents 6 tables with data and only several rows I show at once.

app.js

v         


        
相关标签:
4条回答
  • 2021-02-11 22:25

    If you want to open angular page in a new tab on ctrl+click or in same tab, then try this :-

    HTML :

    <a ng-click="navigationUrl($event)">My Link</a>
    

    JS:

        var navigationUrl = function (event) {
                if (event.ctrlKey) {
                    window.open(url, '_blank'); // in new tab
                } else {
                    $location.path(url); // in same tab
                }
            };
    
    0 讨论(0)
  • 2021-02-11 22:40

    You are opening a new window using another function which could get Angular confused.

    Try passing the string in the $window.open(real_path) where real_path is a string containing the path you want to navigate

    0 讨论(0)
  • 2021-02-11 22:43

    One more option is to use ng-href

    HTML:

     <a  ng-href="#/courses/{{employee.courseId}}/employees/{{employee.id}}" 
          target="_blank"> {{employee.employeeNumber}}
     </a>
    

    Where url is based on where you want to redirect

    0 讨论(0)
  • 2021-02-11 22:43

    For opening a new view in a new window, execute the following code:

    window.open($location.$$absUrl.replace($location.$$path,NEW_PATH), '_blank');
    
    0 讨论(0)
提交回复
热议问题