I have an array of students which I present their names in a list and below each name two buttons that allow them to be assigned a grade, either positive or negative.
What I want to do is that when I click on the button (positive or negative) it shows a message and hides the buttons div
I share what I have below:
HTML view
<ul class="ejemplo" ng-app ng-controller="sample">
<div ng-repeat="i in estudiantes">
<h5>{{i.nombres}}</h5>
<div class="botones">
<input type="button" data-ng-click=calificar($event,i.id) value="calificacion positiva" id="1"/>
<input type="button" data-ng-click=calificar($event,i.id) value="calificacion negativa" id="2"/>
</div>
</div>
</ul>
controller.js
function sample ($scope) {
$scope.estudiantes = [
{
nombres: 'Diego Israel',
id: 2
},
{
nombres: 'Juan Carlos',
id: 3
},
{
nombres: 'Pedro',
id: 4
}
];
$scope.calificar = function(event,id){
var estado = event.target.id;
switch (estado) {
case '1':
//para no mostrar este alert quiero ocultar el div botones y mostrar el respectivo mensaje
alert('calificacion positiva');
break;
case '2':
//para no mostrar este alert quiero ocultar el div botones y mostrar el respectivo mensaje
alert('calificacion negativa');
break;
default:
return false;
}
}
}
The idea is that once the button has been clicked, automatically below the name of the selected student the message I hope I have made myself understood is displayed. I thank you in advance
Put a boolean variable in the scope of your controller. Set
ng-show
orng-hide
equal to your variable on the DOM element you want to hide, and change the value of your boolean on the switch.I was able to solve it, I share the answer:
I don't know Angularjs or ng-repeat, but if you can load the page with your data according to this model, it should work as you say:
If you need any clarification, you know where I am.