Angular uiRouter open state in new window or tab with stateParams

前端 未结 2 821
天命终不由人
天命终不由人 2021-02-09 07:56

What I want to do is following in but in a new Tab or new Window:

$state.go(\'studentsReport\', {
       type: $scope.report.type, // string
       selectedStude         


        
相关标签:
2条回答
  • 2021-02-09 08:08

    You should trying to use this:

    /* @ngInject */
    function SomeCtrl ($state, $window) {
      $window.open($state.href('stateName', {}, {absolute: true}), '_blank');
    }
    

    Note: the /* ngInject */ facilitates automatic dependency injection annotation if using ng-annotate (available in cli, gulp, and grunt flavours)

    0 讨论(0)
  • 2021-02-09 08:09

    use ng-click on link tag and call a function. in function put your parameters in LocalStorage. then in app.run use $rootScope.$on("$stateChangeStart") and check if localstorage have parameters get params and call $state with params.

    //in page controller: 
    var openNewTab = function () {                  
                        localStorage.newTab = JSON.stringify({
                            state: "yourState",
                            params: {
                                param1: "someparam1",
                              param2:"someparam2"
                            }
                        });                  
                        window.open(document.location.origin);
                          
                    }
     
     //angular app run config: 
    angularApp.run(function($state){
    if(localStorage.newTab){
       var newTab = JSON.parse(localStorage.newTab);
       localStorage.removeItem("newTab");
       $state.go(newTab.state, newTab.params);
       event.preventDefault();
    }
    })
    <a ng-click="openNewTab()" >open new tab</a>

    0 讨论(0)
提交回复
热议问题