<button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); }
What I want is post a require and open the response html in a new tab when you click the "openTab" button. There is no method to do this with $http
. I think this maybe simple, but I can't find a way.
AngularJs open link in new tab – you'll use $window service to open a link in new tab in angularjs.
The $window service in AngularJS refer to the browser window object. With reference to JavaScript, window is a global object that includes many methods like prompt, conform, alert, etc. With window object in JavaScript, there is a testability problem due to it is defined as a global variable.
You can do this all within your controller by using the $window service here. $window is a wrapper around the global browser object window.
To make this work inject $window into you controller 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
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