Skip to main content

How to use ngClick in angularJs

ngClick

            What is ngClick ?

                  An ngClick directive to allow a customer even handling functions. An html element make any click event logic is need to implement ng-click in DOM. 

Syntax: 

    <input type ="anytype" ng-click="function_name()">

How to pass Current Object or Event ?

When we want get current clicked dom object properties is need means we pass $event  param to corresponding method.

   <input type ="anytype" ng-click="function_name($event)">


Example :

<div ng-app="appClick">
    <div ng-controller="appController">
        <input type="button" value="Click" ng-click="showClick()" />
        <input type="button" name="buttonClick" value="click+Event" ng-click="showClickEvent($event)" />
    </div>
</div>

Java Script:

var appClick = angular.module("appClick",[]);
appClick.controller("appController",['$scope', function($scope){
    $scope.showClick = function() {
        alert('ng-click function');
    }
    $scope.showClickEvent = function(obj) {
        alert(obj.target);
        alert(obj.target.name);
        alert(obj.target.type);
        alert(obj.target.value);
    }
}]);

Result : 


    

Comments

Popular posts from this blog

How has lockdown impacted Indian farmers?

How has lockdown impacted Indian farmers?             Generally compare to other sectors it's not major impacted by our Indian farmers but we acceptable minor impacts. Here we separate major two farming cultures one is mono farming culture another one poly farming culture. Mono farming :             The major impacts from our Indian farmer for monoculture. Here I have briefly explained what are the things we had faced our local farmers. Here I explain two different crops type: Daily crops : * We harvest more than 100-kilo grams daily crops like brinjal but we unable to sell those in local markets. * We are unable to reach urban markets. * We don't have enough transport facilities. * We unable buy require fertilizer and other complements * In the early stage we are facing manpower shortage but later it's not an issue. * We unable to do value-added products. * Waste is very high for somedays Se...

Timer Display using AngularJS

Timer Display To display timer in a page means, we need to aware of angular directive as following $interval and $filter . Current time get from new Date() object from native java script.   $interval Directive:  A interval is wait into a millisecond or trigger to a function, This function many many time to repeatedly calling process is control to us.   Syntax:  $interval(fn, delay, [count], [invokeApply]); fn - a function to call repeatedly. Delay – number of millisecond to call a function. Count – Number of time to repeat.(0 value means no-repeat) invoteApply – set to false means it will skip. Example:  HTML: <div ng-app="timerApp">     <div ng-controller="timerController">         {{time}}     </div> </div> JAVAScript: var app = angular.module("timerApp", []); app.controller("timerController",['$scope','$interval...

Radio Button Selection using AngularJS

How to use radio button in angularJS    Radio button selection is apply to angular ng-click event method, this method passing param is $event Object. This $event  Object have corresponding radio button properties will return.   Radio Button angular properties  ngModel string It's to angular refer the bind properties  value string To get value or set value from the radio button  name string Property name of the form radio button. ngChange string To make event from the radio button ngValue string Angular expression value  Radio Button Example : HTML: <div ng-app="radiobtn">     <div ng-controller="radioController">         Select your favourite food <br/>         <input type="radio" name="fav" ng-model="fav_food" value="curd rice" ng-click="getFood($event)" />curd rice<br/>             <input ty...