simbada simbada - 1 year ago 91
AngularJS Question

finding property with true flag in an object

I have an object with three properties.

$scope.badges = {'Full Service': false, 'Negotiable': true, 'Under Warranty': false};

How do i
extract OR find property
from it with

Basically, i want to find property from this object having true flag and then assign it to another scope variable.


<div ng-repeat="(badge,enabled) in badges" class="checkbox">
<input type="checkbox" ng-model="badges[badge]" /> {{badge}}

Angular Controller

$scope.badges = {
'Full Service History': false,
'Negotiable': false,
'Under Warranty': false,
' Urgent': false

I want to see which checkbox user has selected.

Answer Source

A much cleaner solution:

$scope.activeKeys = [];
for (var key in $scope.badges) {
    if ($scope.badges[key]) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download