I have an array with people's objects and the name and menu attributes for a dinner.
I want to paint them in the HTML with ng-repeat and each member will have a set of radio buttons so that, if they want to change the menu, I collect the information and update in the future in the BBDD what menu will take.
HTML:
<main ng-app="easterMenu" ng-controller="memberCtrl">
<div class="container">
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="membership" ng-repeat="member in fellowship">
<h3 class="membership__name">{{ member.name }}</h3>
<input id="cordero-{{$index}}"
type="radio"
name="menu-{{$index}}"
ng-value="cordero"
ng-model="$parent.menuSelected"
ng-checked="{{member.menu == 'cordero'}}"
ng-change="selectMenu($index)">
<label for="cordero-{{$index}}">Cordero</label>
<input id="infantil-{{$index}}"
type="radio"
name="menu-{{$index}}"
ng-value="infantil"
ng-model="$parent.menuSelected"
ng-checked="{{member.menu == 'infantil'}}"
ng-change="selectMenu($index)">
<label for="infantil-{{$index}}">Infantil</label>
</div>
</div>
<p>{{ menuSelected }}</p>
</div>
</div>
</main>
JS:
var app = angular.module('easterMenu', []);
app.controller('memberCtrl', ['$scope', '$http', function($scope, $http) {
$scope.fellowship = [
{
name: "Pepe",
menu: "cordero"
},
{
name: "María",
menu: "infantil"
},
{
name: "Juan",
menu: "cordero"
}
];
$scope.selectMenu = function(index) {
console.log(index);
console.log($scope.menuSelected);
};
}]);
The ng-change is not running and the ng-model is not updated, other times it selects the radio buttons of all at the same time, every time it happens to me a different thing I think the ng-value may be the problem, but I'm already lost and I can not find a solution for the forum or the Internet.
AngularJS version: 1.6.3
Thanks to everyone who can and wants to help me.
Greetings.