neptune neptune - 1 year ago 109
AngularJS Question

Open a new tab on button click in AngularJS

<button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button>

openTab = function () {

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
I think this maybe simple, but I can't find a way.

Answer Source

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(){
            $'', '_blank');

this works well when redirecting to dynamic routes

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download