HappyCoding HappyCoding - 2 years ago 119
AngularJS Question

Write event onclick not via using ng-click in angularjs

I want to set event

for an object not via using
like jQuery syntax:

<button>Click me</button>
$('button').click(function () {
alert('Hello World!')

My question, is there a way to write event
like that in angularjs?

I don't want to use this way:

<button ng-click="sayhello()">Click me</button>

angular.module('myModule', []).controller('myController', function ($scope) {
$scope.sayhello = function () {
alert('Hello World!');

I want to hide the information
in the html.

Answer Source

Try angular.element:

var ele = angular.element('button');

Same Jquery Code:

ele.click(function () {
   alert('Hello World!')


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download