Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use onClick with angularJs?

Tags:

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.

like image 329
abhit Avatar asked Nov 04 '16 11:11

abhit


People also ask

Can we use Onclick in angular?

the Angular 2 onClick Event The Angular 2 event system can be used to handle different types of events, such as mouse clicks, keyboard presses, and touch gestures. The onclick event triggers an event or function when a user clicks on a component or an element.

What is Ng-click function in AngularJS?

The ng-click Directive in AngluarJS is used to apply custom behavior when an element is clicked. It can be used to show/hide some element or it can pop up an alert when the button is clicked. Parameter Value: expression: It specifies when the particular element is clicked then the specific expression will be evaluated.

Can we use NG-click and Onclick together?

For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.

Can we use NG-click in Div?

Syntax of using ng-click directive There, the button is an element that can be replaced by any other HTML element like a link, span, paragraph, div etc.


Video Answer


2 Answers

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>
like image 163
devqon Avatar answered Sep 30 '22 06:09

devqon


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;
}
like image 27
Pankaj Parkar Avatar answered Sep 30 '22 06:09

Pankaj Parkar