Controlling Food Choices
.controller('FoodController', function($scope, $ionicPopup) {
$scope.favorite = { 'food': 'egg' };
$scope.setFavoriteFood = function() {
var popup = $ionicPopup.show({
'templateUrl': 'popup-favorite.html',
'title': 'Favorite Food',
'subTitle': 'Please pick your favorite food',
'scope': $scope,
'buttons': [
{
'text': '',
'type': 'button-assertive icon ion-close-round'
},
{
'text': '',
'type': 'button-balanced icon ion-checkmark-round',
'onTap': function(event) {
console.log($scope.favorite.food);
return $scope.favorite.food;
}
}
]
});
popup.then(function(result) {
console.log('Your favorite food is: ' + result);
});
};
}
Custom Popup Template
<script id="popup-favorite.html" type="text/ng-template">
<ion-list>
<ion-radio ng-model="favorite.food" ng-value="egg">Egg</ion-radio>
<ion-radio ng-model="favorite.food" ng-value="tomato">Tomato</ion-radio>
</ion-list>
</script>
The issue with the data binding between $scope.favorite.food
and radio buttons has been identified. Interestingly, replacing the radio buttons with a single input field
<input type="text" ng-model="favorite.food">
resolves this problem.
How can I ensure that my radio buttons function correctly as expected?