AngularJS onclick call function
If you are trying to call function on button click using AngularJs please use below code:
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>AngularJS on click function call</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script> <script> var app = angular.module('myApp', []); app.controller('controller', ['$scope', function($scope) { $scope.function1 = function(msg) { alert(msg + ' first function call!'); }; $scope.function2 = function(msg) { alert(msg + ' second function call!'); }; }]); </script> </head> <body> <div data-ng-app="myApp"> <div data-ng-controller="controller"> <button data-ng-click="function1('AngularJS')">Call first function</button> <button data-ng-click="function2('AngularJS')">Call second function</button> </div> </div> </body> </html>
Output:
This is THE most concise example of this type of behavior I have seen in learning.
wow…thank a lot 🙂
I’d like to call two functions with just one click, how can I do this in angularJS?
tested