1

How can we trigger the button click event using AngularJs and show an alert message box? I have tried the alert("message") messagebox but it doesn't work.

1

2 Answers 2

3

You can use ng-click on button something like this:

Controller :

   var VLogin = angular.module('myApp',[]);
   VLogin.controller('TestCtrl', ['$scope',function($scope) {

   $scope.clicked = function(){
        alert("Clicked");
    }
}]);

And in your HTML like :

<div ng-app="myApp">
    <div ng-controller="TestCtrl">
      <button ng-click="clicked()">Click me!</button>
    </div>
</div>

Here is the working Fiddle :- http://jsfiddle.net/nuejh9h6/

Thanks

Sign up to request clarification or add additional context in comments.

Comments

0

we need to see what you have wrote but in general this is how ng-click works https://docs.angularjs.org/api/ng/directive/ngClick and you can write your alert code inside or in a new method and call it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.