Basically I want my app to open links in new tab/page when user holds down Ctrl (on linux windows), Cmd (on OSX). What is the way to go.
Note: I cannot get rid of ng-click. the application uses it various method calls within scope.
Basically I want my app to open links in new tab/page when user holds down Ctrl (on linux windows), Cmd (on OSX). What is the way to go.
Note: I cannot get rid of ng-click. the application uses it various method calls within scope.
Try this:
In HTML,
<div ng-click="gotoPageOrFunc($event)"></div>
In JS,
$scope.gotoPageOrFunc = function(event){
if (event.ctrlKey==1){
// Use windows.location or your link.
}else{
// Your actual functionalities.
}
}
Use directive.
angular.module('myapp').directive('newtab', function() {
return {
restrict: 'AC',
link: function($scope, $elem) {
var target = $elem.attr('target');
$elem.on('click', function(e) {
target = $elem.attr('target');
$elem.attr('target', '_blank');
});
$elem.on('blur', function() {
$elem.attr('target', target);
});
}
};
});
// UPD
usage
<a href="/my/page?foo=bar" class="newtab">xoxo<a/>
or
<a href="/my/page?foo=bar" newtab>xoxo</a>
or
<a href="/my/page?foo=bar" data-newtab>xoxo</a>
// UPD 2
<a href="/my/page?foo=bar"
data-ng-click="myControllerMethod()" class="newtab">xoxo<a/>
or
<a href="/my/page?foo=bar"
data-ng-click="myControllerMethod()" newtab>xoxo</a>
or
<a href="/my/page?foo=bar"
data-ng-click="myControllerMethod()" data-newtab>xoxo</a>
myControllerMethod()
starts to evaluate, you've left the page, possibly terminating it. –
Heilner This might help you
HTML
<a ng-click="getPreviousURL()" href="https://www.google.com/unlimited-plan/">More.../a>
JS
$scope.getPreviousURL = function(moreurl,category,returnurl) {
var revrl=category+'bundles';
$window.localStorage.setItem('prev_url',revrl);
**var target = $elem.attr('href');**
**window.location = target;**
};
© 2022 - 2024 — McMap. All rights reserved.
<a href="/somePath">click here</a>
. – Torse<a>
or could it be also something else, like<div>
? – Snapp