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.
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
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'; }