Angularjs $state open link in new tab

前端 未结 7 2088
遇见更好的自我
遇见更好的自我 2020-12-01 00:36

I\'m trying to implement an \"open link in new tab\" function using $state.go function. It would be awesome if there was smth like:

$state.go(\'routeHere\',          


        
7条回答
  •  北海茫月
    2020-12-01 01:23

    The best answered I found, was extending the ui.router, since the feature, does not exist build in. You may find the full detail here :

    Extending the Angular 1.x ui-router's $state.go

    However, here is my short explanation of what needs to be done add this to app.js or angular app init file:

    angular.module("AppName").config(['$provide', function ($provide) {
        $provide.decorator('$state', ['$delegate', '$window',
            function ($delegate, $window) {
                var extended = {
                    goNewTab: function (stateName, params) {
                        $window.open(
                            $delegate.href(stateName, params, { absolute: true }), '_blank');
                    }
                };
                angular.extend($delegate, extended);
                return $delegate;
            }]);
    }]);
    

    In your code

    You will be able to do:

    $state.goNewTab('routeHere', { parameter1 : "parameter"});
    

提交回复
热议问题