Sajith Sajith -4 years ago 67
AngularJS Question

Adding class to an element on its click event

I am new to Angular Js. I need to add a class to an element on its click event. I tried the following code. But it is not working.


<script src="js/lib/jquery.min.js"></script>
<script src="js/lib/angular.min.js"></script>
<body ng-app="MyApp" ng-controller="MyController">

<div ng-repeat="data in datas">
<p ng-click='selectMe()'>{{}}</p>

var app = angular.module('MyApp',[]);
$scope.datas = [{name:"first"},{name:"second"}];

$scope.selectMe = function (){


What is the problem in this code? Is it necessary to use ng-class ? How to do it?

Answer Source

You can pass $event to click

<p ng-click='selectMe($event)'>{{}}</p>

$scope.selectMe = function (event){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download