Open a new tab after button click in AngularJS


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

openTab = function () {
  $http.post('www.google.com');
}

What I want is to post a requirement and then open the response html in a new tab when the "openTab" button is clicked. Unable to use to do this $http. I think it might be simple, but I can't find a way.

Aaron

You can do everything in your controller here using the $window service . $window is a wrapper around the global browser object window.

To do this, inject $window into the controller as follows

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

Works great when redirecting to dynamic routes

Related


Open a new tab after button click in AngularJS

Neptune: <button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } What I want is to post a requirement and then open the response html in a new tab when the "openTab" button

Open a new tab after button click in AngularJS

Neptune: <button type="button" class="btn btn-primary" ng-click="openTab()">new tab</button> openTab = function () { $http.post('www.google.com'); } What I want is to post a requirement and then open the response html in a new tab when the "openTab" button

Click the button to open a new tab

Nathan Wilson I want to create a link with a button that opens in a new tab. The code I'm currently using is currently opening a blank tab and I'm not sure why. <div class="text text-left"> <h2>WORK</h2> <h1>Title</h1> <p>Lorem ipsum dolor sit am

Click the button to open a new tab

Nathan Wilson I want to create a link with a button that opens in a new tab. The code I'm currently using is currently opening a blank tab and I'm not sure why. <div class="text text-left"> <h2>WORK</h2> <h1>Title</h1> <p>Lorem ipsum dolor sit am

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Open new tab on button click using JQUERY

Rajan My scene is like this: I have edit user module. Each user is assigned a base INI file . When we edit a user, we have a drop down menu from which to select his base INI file. After selection, we can save the user. And the ID of the selected file is also s

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Open new tab on button click using JQUERY

Rajan My scheme is this: I have edit user module. Each user is assigned a base INI file . When we edit a user, we have a drop down menu from which to select his base INI file. After selection, we can save the user. And the ID of the selected file is also saved

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Protractor button click and open page in new tab

Sumitomo I am new to protractor. I'm trying to automate a scenario where I click a button and it opens a page in a new tab and then we need to populate the form in the new page and submit it. Problem : When I click the button to open a new page. My tests don't

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Click Primefaces in a new tab on the button to open the page

username i have this <h:outputLink value="http://.....index.html" target="_blank">open</h:outputLink> But it shows up as a link. How to create a similar button? I need the "Open" button. When I press this button I need to open the link in a new tab in the bro

Open new tab on button click using JQUERY

Rajan My scheme is this: I have edit user module. Each user is assigned a base INI file . When we edit a user, we have a drop down menu from which to select his base INI file. After selection, we can save the user. And the ID of the selected file is also saved

Swift - Open new view after button click

Drake I want to open new view after button click. But when I create via UIButton in Main.storyboard it's ok, since I have to use some if statements in login/password I need to create in code. I've tried to make it like suggested in other similar questions, but

Swift - Open new view after button click

Drake I want to open new view after button click. But when I create via UIButton in Main.storyboard it's ok, since I have to use some if statements in login/password I need to create in code. I've tried to make it like suggested in other similar questions, but

Swift - Open new view after button click

Drake I want to open new view after button click. But when I create via UIButton in Main.storyboard it's ok, since I have to use some if statements in login/password I need to create in code. I've tried to make it like suggested in other similar questions, but

Swift - Open new view after button click

Drake I want to open new view after button click. But when I create via UIButton in Main.storyboard it's ok, since I have to use some if statements in login/password I need to create in code. I've tried to make it like suggested in other similar questions, but

Swift - Open new view after button click

Drake I want to open new view after button click. But when I create via UIButton in Main.storyboard, it's ok, since I have to use some if statements in login/password, I need to create in code. I've tried to make it like suggested in other similar questions, b

Swift - Open new view after button click

Drake I want to open new view after button click. But when I create via UIButton in Main.storyboard, it's ok, since I have to use some if statements in login/password, I need to create in code. I've tried to make it like suggested in other similar questions, b

Alert on button click and move user to open new tab

Dashan I created a button with a link that opens in a new tab. I also used JavaScript for reminders. Currently this code works fine. But after clicking OK in the Alert, the user stays on the same page. But I want to move the user to the newly opened tab. is it

button click: open a new browser tab and call a function

fiber I have a button which calls a function: Perform an AJAX PHP request to the database Display the retrieved data in a div container scroll to div container with bookmark (#) I want a button to do the same task, but with one action, which is to open a new t