I want to use a for-in loop to check if items in an object are undefined. However the loop will only run if there are already values stored in the object.
Here's an example of how I'm putting values into the object:
<div>
<input type="radio" name="" id="" ng-model="user.fac_staff" value="">
<input type="radio" name="" id="" ng-model="user.fac_staff" value="">
<input type="radio" name="" id="" ng-model="user.fac_staff" value="">
</div>
<div>
<select class="" id="" name="" ng-options="ng repeat stuff" data-ng-model="user.college">
<option value="">Stuff</option>
</select>
</div>
<div>
<input type="radio" name="" id="" ng-model="user.source" value="">
<input type="radio" name="" id="" ng-model="user.source" value="">
<input type="radio" name="" id="" ng-model="user.source" value="">
</div>
<input type="text" class="" name="" id="" data-ng-model="user.name_awarding_agency">
<button type="submit" ng-click="ajs_function(user)">Click</button>
Here's an example of what I'm trying to do in the controller:
$scope.ajs_function = function(userObj) {
for(var key in userObj) {
if(userObj[key] == "undefined")
//do stuff
}
}
The loop won't run at all. I've tried to display the key values to the console, and when that didn't work I tried to display a counter value to the console just to see if it was doing anything at all. I should also mention that I have a similar for-in loop in a function going through the same object, however that loop only runs when there is already data.