I have four values with names :
$scope.restaurant.restaurantIsTop
$scope.restaurant.restaurantIsRecommended
$scope.restaurant.restaurantIsNew
$scope.restaurant.restaurantIsPromoted
Each of them can be 0 or 1 . I want to check them if their value is equal to 1 , change it to true , otherwise it would be false.
I could do this with this method for four variable:
if ($scope.restaurant.restaurantIsTop == 1 ?
$scope.restaurant.restaurantIsTop = true :
$scope.restaurant.restaurantIsTop = false);
if ($scope.restaurant.restaurantIsNew == 1 ?
$scope.restaurant.restaurantIsNew = true :
$scope.restaurant.restaurantIsNew =false);
if ($scope.restaurant.restaurantIsRecommended == 1 ?
$scope.restaurant.restaurantIsRecommended = true :
$scope.restaurant.restaurantIsRecommended =false);
if ($scope.restaurant.restaurantIsPromoted == 1 ?
$scope.restaurant.restaurantIsPromoted = true :
$scope.restaurant.restaurantIsPromoted =false);
Absolutely it works but It's not efficient way for multiple value. So I created an array :
var varietyArray = ["restaurantIsTop" ,
"restaurantIsRecommended",
"restaurantIsNew",
"restaurantIsPromoted"
];
angular.forEach (varietyArray, function (val) {
console.log($scope.restaurant.val);
})
And I want to check four variable in above loop . Any suggestion ?
EDITED :
I want to show them in Angular Material checkbox :
<div class="col-sm-12">
<div class="md-form-group">
<md-checkbox ng-model="restaurant.restaurantIsTop ">
best
</md-checkbox>
<md-checkbox ng-model="restaurant.restaurantIsRecommended">
suggested
</md-checkbox>
<md-checkbox ng-model="restaurant.restaurantIsNew">
new
</md-checkbox>
<md-checkbox ng-model="restaurant.restaurantIsPromoted">
promote
</md-checkbox>
</div>
</div>
0and1is by defaultfalsyandtruthy. if you make changes on same variable, it'll changes it's meaning. You wanna display on view true or false ? or it's just for internal calculation ?