Farris Ismati Farris Ismati - 2 years ago 66
AngularJS Question

How to change an object's property in AngularJS

I have a function that sets a property in an object to false if it's true and true if it's false. Yet every time the function runs the object doesn't get affected.

$scope.menuButtons = [{header: "beaded", isActive: false},
{header: "laced", isActive: false}

$scope.activeButton = function(isActive) {
isActive == true ? isActive = false : isActive = true;

Here's the HTML

<div ng-repeat="b in menuButtons">

<div ng-click="activeButton(b.isActive)" class="shop-navbar-button">{{b.header}}</div>


I'm using the isActive value to see if the button is active so I can use a different class. For some reason the isActive value in the $scope doesn't get affected.

Answer Source

Pass in b instead of b.isActive. The boolean is just being passed by value, so re-assigning the value will have no effect on b.isActive.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download