new tab openTab = f...">

Open a new tab when a button is clicked in AngularJS

<button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } 

I want the message to be needed and open the html response in a new tab when you click the "OpenTab" button. There is no $http method for this. I think it might be simple, but I cannot find a way.

+58
javascript angularjs
Jul 20 '13 at 1:43
source share
3 answers

You can do all this in your controller using the $ window service here . $ window - a wrapper around the window of the global browser object.

To make this work, insert $ window into the controller in it as follows

 .controller('exampleCtrl', ['$scope', '$window', function($scope, $window) { $scope.redirectToGoogle = function(){ $window.open('https://www.google.com', '_blank'); }; } ]); 

this works well when redirecting to dynamic routes

+132
Aug 22 '14 at 5:29
source share

I solved this issue this way.

 <a class="btn btn-primary" target="_blank" ng-href="{{url}}" ng-mousedown="openTab()">newTab</a> $scope.openTab = function() { $scope.url = 'www.google.com'; } 
+12
Nov 08 '13 at 4:29
source share

You must use the $location service

Angular docs:

0
Sep 23 '13 at 15:46
source share



All Articles