I must change the true and false that arrive from my controller, I am working with ASP.net and the true and false arrive now I need to rename in the view look at the state.
I made this code and it only works for the first value that appears to me out of n elements.
<table class="table table-striped">
<tr>
<th>Codigo</th>
<th>Nombre</th>
<th>Estado</th>
</tr>
<tr ng-repeat="e in ListaDosificacion" ng-class-even="'even'" ng-class-odd="'odd'">
<td>{e.Codigo}}</td>
<td>{{e.Nombre}}</td>
<td>
<b><p id="EstadoFalse" style="color:red"></p></b>
<b><p id="EstadoTrue" style="color:blue"></p></b>
<input type="submit" id="btnEstado" value="{{ e.Estado }}" class="form-control" onclick="estado()" />
<script type="text/javascript">
setTimeout(function () { document.getElementById("btnEstado").click(); }, 100);
function estado() {
var estado = document.getElementById("btnEstado").value;
if (estado == "true") {
document.getElementById("EstadoTrue").innerHTML = "Activo";
}
if (estado == "false") {
document.getElementById("EstadoFalse").innerHTML = "Inactivo";
}
}
</script>
</td>
</tr>
</table>
It only works for you in the first one because you are creating a conflict with the "Ids". An Id is a unique identifier of an element, but by creating this, inside an ng-repeat you are creating multiple buttons with the id "btnEstado"
My suggestion, use classes instead of id
After the script, you write it to the end of the document.
Everything being something like this
Assimilating that you need to show the states of one color or another depending on whether it is active or not, I attach the following code:
There are certain things that I didn't understand about your code, for example that you are showing a
submit
and you are assigning the value to thise.Estado
; and above you assign colors depending on the same state. I guess you wanted to paint the status register one color or another depending on its value (true/false) , so I stuck to that intuition to answer you.Another thing, if you are going to use
AngularJS
, which is a very powerful Framework, you should try to fully use its functionalities, for example useng-click
to the detriment of the factonclick
that it is clearlyJavascript
.Greetings and excellent code colleague!