elykl33t
elykl33t

Reputation: 997

Open a new window in AngularJS

I know this is simple and a dumb question but I can't for the life of me make this work for some reason...

So I have a link (based on a non-angular popup using onclick):

<a href="page.html" ng-click="popitup('page.html')">Page</a>

And a function within the scope:

$scope.popitup = function(url) {
  return $window.open(url, '_blank', 'height=200,width=150');
};

All I want is, when someone clicks the link, open a new window and display page.html. I have tried changing small parts of the link and the function, but I can't get it. I'm sure it's something small I am doing wrong.

Upvotes: 1

Views: 15668

Answers (2)

Mastro
Mastro

Reputation: 1497

This worked for me.

html

 <a data-ng-click="openPrintMode()">
                            <i class="fa fa-print"></i>
                        </a>

controller

$rootScope.openPrintMode = openPrintMode;

function openPrintMode() {
            $window.open($location.$$absUrl + "?v=p", "_blank");
        }

Upvotes: 0

Swapnil Patwa
Swapnil Patwa

Reputation: 4099

Try this.. In HTML

  <body ng-controller="MainCtrl">
  <a  role="link" ng-click="popitup('page.html', '_blank')">Page</a>
  </body>

In controller

app.controller('MainCtrl', function($scope, $window) {
  $scope.popitup = function(url, target) {
  $window.open(url, target);
};
});

plunker

Upvotes: 2

Related Questions