Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a toggle ng-click event

I have been able to create a function to successfully toggle the rows in my ng-table to expand on click, however, when clicking them again they will not hide. The function in the javascript is:

$scope.toggle = function() {
    return !this.booleanVal;
}; 

The booleanVal is being a value from the json file (each row with its own value). Then in the HTML.

<p class="row_description more" ng-click="row.booleanVal = toggle()">{{row.description}</p>
<div class="check-element animate-show" ng-show="row.booleanVal">

It works for the first click, turning the previously false booleanVal to true, however, it doesn't toggle back to false. Any idea what's going wrong?

like image 935
Kylie Moden Avatar asked Jun 23 '14 20:06

Kylie Moden


People also ask

Can we use NG-click and Onclick together?

For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.

What is the difference between Ng-click and Onclick?

Another significant difference between ng-click and onclick is the execution context. Code inside an onclick attribute executes against the global window object, while an expression inside of ng-click executes against a specific scope object, typically the scope object representing the model for the current controller.

Can we call two functions on Ng-click?

In this article, we will learn how to get many/multiple functions to the ng-click directive passed, in just one click. The key is to add a semi-colon (;) or a comma (,). All the functions must be separated by a (;) or a (, ). This syntax is supported by all the elements in the HTML.


1 Answers

Try this:

<p class="row_description more" ng-click="row.booleanVal = !row.booleanVal">
    {{row.description}
</p>
<div class="check-element animate-show" ng-show="row.booleanVal"></div>
like image 135
Mathew Berg Avatar answered Nov 15 '22 20:11

Mathew Berg