I have an old system and for example the user can do a click-right new table on some link and in new tab the system will be open in same page, but now I built a new system SPA with angularjs and my users want the same funcionality but always that I open new tab the system open in the main page, of course is a SPA and the system not sabe the context. I think that I need create a storage to create this, but will be a good practices?
Asked
Active
Viewed 2,765 times
-1
-
https://stackoverflow.com/questions/23516289/angularjs-state-open-link-in-new-tab – Shantanu Jul 10 '17 at 16:51
-
In your example is to always open in a new tab, but in my case I need just when the user click the right mouse button. – Diogo Soares Jul 10 '17 at 17:37
1 Answers
1
If you want it to work only on right click then use the below function on ng-mousedown with passing $event to it. check the right click event & then open state in new tab.
$scope.openInNewTab = function(e){
//console.log(e.button);
if(e.button === 2) {
var url = $state.href('PageTab.Page2', {});
window.open(url,'_blank');
}
}
<p ng-mousedown="openInNewTab($event)">Open page 2 in new tab</p>
Here's working plunker link: https://plnkr.co/edit/mo96eXMLKfHkUWPKPG2m?p=preview

Shantanu
- 3,483
- 2
- 17
- 20
-
Sounds Good! But in this example You used the pages in URL in my case I use hide, I show just the domain all the pages run under of "/" and with this example not work – Diogo Soares Jul 11 '17 at 14:16
-
How are you using routing in your application? (Are you using $routeProvider or $stateProvider to define routes? Or you haven't implemented routing?) – Shantanu Jul 11 '17 at 15:49
-
$stateProvider .state('fornecimento/info', { url: '/', templateUrl: 'views/fornecimento/info.html', params: { IDF: null, Contrato: null } }) – Diogo Soares Jul 11 '17 at 16:22
-
So you've separate state for this purpose right? (to open in new tab)? In my answer $state.href('PageTab.Page2, {}'), PageTab.Page2 is the state name it's not a path name.. So even if you've '/' path for all your states this solution should work – Shantanu Jul 11 '17 at 16:28
-
Yes, can be! I am thinking in to do this, but the parameters not work in new tab. I try to test in your example but also not work. I pass the parameters but in new tab not take. – Diogo Soares Jul 11 '17 at 16:32