Sunny Khanuja
Sunny Khanuja

Reputation: 103

AngularJs scope variable window.open

I have a AngularJs Application in which I want to pass scope variable to onclick="window.open('{{portfolio.link}}', '_system');"

My Code :

<a class="item item-avatar txtShow" onclick="window.open('"{{portfolio.link}}"', '_system');" ng-repeat="portfolio in freelancer.portfolio">
  <img class="portfoliobg" src="{{portfolio.image}}">
  <h2>{{portfolio.name}}</h2>
  <p>{{portfolio.description}}</p>
  <h5>Added On :{{portfolio.adddate}}</h5>
</a>

Here my angularJS variable is not working and its taking it as simple text

Upvotes: 3

Views: 1802

Answers (1)

chenware
chenware

Reputation: 869

Ran into a similar problem and ended up using a function in my controller to make it work.

    <a class="item item-avatar txtShow" ng-click="openPortfolioURL()">
  <img class="portfoliobg" src="{{portfolio.image}}">
  <h2>{{portfolio.name}}</h2>
  <p>{{portfolio.description}}</p>
  <h5>Added On :{{portfolio.adddate}}</h5>
</a>

Then in the controller:

$scope.openPortfolioURL = function() {
    try {
        var portfolioURL = $scope.portfolio.link;
        window.open(portfolioURL, '_system');
    } catch (err) {
        alert(err);
    }
}

Credit to the Ionic forums.

Upvotes: 3

Related Questions