I am looking to retrieve only the keys with a true value in the data object and display them in the console with the specified format:
Object {
Agent=true,
Analytics / Business Intelligence=true,
Architecture / Interior Design=false
}
The categories are listed in ng-model checkbox inputs on the front end like this:
<li ng-repeat="ai in industry | filter:searchByIndustry" class="checkbox">
<label>
<input type="checkbox" class="css-checkbox" id="checkboxCategories{{ai.id}}" ng-model="dataCategory[ai.name]" />
<label class="css-label chrome-style" for="checkboxCategories{{ai.id}}">{{ai.name}}</label>
</label>
</li>
When a user checks the checkbox, the category name is assigned a value of true. On unchecking, it becomes false. I want to store the true values in a string in my Angular controller.
$scope.$watch(function () {
return {
useCat :$scope.dataCategory
}
}, function (value) {
var searchMeta = [];
for( var l in value.useCat ) {
if (l==true) {
//code
searchMeta.push(l)
}
}
console.log($scope.searchMeta);
}, true );