I'm having a problem with a label, I want to change the id (that varies by number depending on the table that belongs) and on the line:
document.getElementById('labelUsuario').id = "" + numeroMesa + "";
I get the following error:
angular.js:13920 TypeError: Cannot set property 'id' of null
at ChildScope.$scope.MostrarMesasPorZona (appPedidosMozo.js:42)
at fn (eval at compile (angular.js:14817), <anonymous>:4:332)
at expensiveCheckFn (angular.js:15906)
at callback (angular.js:25885)
at ChildScope.$eval (angular.js:17682)
at ChildScope.$apply (angular.js:17782)
at HTMLButtonElement.<anonymous> (angular.js:25890)
at HTMLButtonElement.dispatch (jquery-1.9.1.min.js:3)
at HTMLButtonElement.v.handle (jquery-1.9.1.min.js:3)
(anonymous) @ angular.js:13920
here I leave my code:
HTML
<body ng-app="myAppPedidoMozo" ng-controller="myCtrlPedidoMozo" style="background-image:url('imagen/Fondo madera.jpg');">
<div class="row" id="divZonas">
<div class="tab" ng-repeat="a in zonas">
<button class="tablinks" id="BtnZona" ng-click="MostrarMesasPorZona(a)">{{a.nombreZona}}</button>
</div>
</div>
<div class="row">
<form class="form-horizontal">
<div id="ZonaSeleccionada" class="tabcontent">
<div class="form-group">
<div class="col-xs-12" id="MesasDiv">
<div ng-repeat="a in mesas" class="col-xs-1" style="margin:5%;">
<button type="button" class="btn btn-warning btn-circle btn-lg" id="{{a.numeroMesa}}">
{{a.numeroMesa}}
</button>
<label id="labelUsuario" style="visibility:hidden;"><i class="fa fa-user-o" aria-hidden="true"></i></label>
ANGULARJS
angular.module("myAppPedidoMozo", []).controller("myCtrlPedidoMozo", function ($scope, $http) {
$http.get('/api/Pedidos/GetPedido/').then(function (response) {
$scope.pedidos = response.data;
});
$scope.MostrarMesasPorZona = function (Zona) {
debugger;
$http.get('/api/Mesas/GetMesasPorZona/' + Zona.idZona).then(function (response) {
$scope.mesas = response.data;
});
document.getElementById('ZonaSeleccionada').style.display = "block";
for (var i = 0; i < $scope.pedidos.length; i++) {
var numeroMesa = $scope.pedidos[i].numeroMesa;
if (numeroMesa === null) {
} else {
document.getElementById('labelUsuario').id = "" + numeroMesa + "";
document.getElementById($scope.pedidos[i].numeroMesa).style.visibility = "hidden";
if ($scope.pedidos[i].idUsuario === null) {
document.getElementById($scope.pedidos[i].numeroMesa).style.color = "red"; }}}}});
an alternative to this was in the html line in the label change it to
<label id="{{a.numeroMesa}}" style="visibility:hidden;"><i class="fa fa-user-o" aria-hidden="true"></i></label>
and thus it would have an id that varies according to the table in question, but the error according to the debugger entered into ExpensiveCheckOld in False. (I have no idea why) if I did not understand wrong it is because it does not recover the table number ({{a.numeroMesa}}) that is why it remains in null, (something of angular) and from there I can not change the properties. I hope you can tell me another alternative or solve this problem.
At the same time, I do not know if the http.Get method to the table api is doing it at the same moment that it tries to recover the id (in the div of the html that is generated by the list of tables) and to the do not yet do the list of tables does not have the element label (I do not know if I explain.) How to solve this because I list the tables after the page load, since I need to do it by zone filter (to the list of tables the charge after clicking on a button of a zone in question)