I have an application with a public page and an admin page. I would like open the admin page in a new tab after login. I've tried this, after the login was successful, but to no effect. The public page (where the login is) is just being reloaded:
var url = $state.href('/admin/overview');
$window.open(url, '_blank');
Any tips would be appreciated. Thank you.
openNewTab = function (url) { $window. open(url, '_blank'); };
The $window service refers to the browser window object. It is globally available in JavaScript, so it causes testability problems. In AngularJS, it is not globally available. It includes various methods like alert box, prompt box, confirms box, etc.
Here is a working JSFiddle, you have to inject $window
before you can use it:
JS:
angular.module('myApp', [])
.controller('dummy', ['$scope', '$window', function ($scope, $window) {
$scope.redirectToGoogle = function () {
$window.open('https://www.google.com', '_blank');
};
}]);
HTML:
<div ng-app="myApp" ng-controller="dummy">
<a ng-href="" ng-click="redirectToGoogle()">Hello</a>
</div>
Here's another working JSFiddle
HTML:
<div ng-controller="MyCtrl">
<a ng-href="{{url}}" target="_blank">Visit jsfiddle</a>
</div>
JS:
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.url ='http://jsfiddle.net/HB7LU/16771/';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With