abhit
abhit

Reputation: 979

How to use onClick with angularJs?

I have written a condition

onclick="window.open({{video_call_url}}, '_system', 'location=yes'); return false;"

here video_call_url is definded in myController as $scope.video_call_url = 'http://www.google.com/';

but when i click the button i am getting an error video_call_url is not defined.

Upvotes: 6

Views: 19063

Answers (2)

Pankaj Parkar
Pankaj Parkar

Reputation: 136194

You could use ng-click, instead of using onclick

ng-click="open(video_call_url)"

$scope.open = function(url) {
  //inject $window inside controller.
  $window.open(url, '_system', 'location=yes');
  return false;
}

Upvotes: 3

devqon
devqon

Reputation: 13997

You can do the logic in the controller:

function myController($scope, $window) {
    $scope.openVideoCallUrl = function() {
        $window.open($scope.video_call_url, "_system", "location=yes");
        return false;
    }
}

And in your view

<a ng-click="openVideoCallUrl()">Open!</a>

Upvotes: 8

Related Questions