0
I’m using $routeParams.idunidade to bring from another screen the id of a unit but the idunidade is always "Undefined" and I can’t understand why, because I’ve used it and it always worked! Will the way of use changed?
Follows my codes:
<div class="row corpo">
<div class="col-ms-12 exibeUnidades">
<div>
<table>
<tr>
<td width="200"><b>Unidade</b></td>
<td width="200"><b>Endereço</b></td>
<td width="200"><b>Bairro</b></td>
<td width="100"><b>Cidade</b></td>
<td></td>
</tr>
<tr ng-repeat="u in unidades">
<td>{{u.unidade}}</td>
<td>{{u.endereco}}, {{u.numero}}</td>
<td>{{u.bairro}}</td>
<td>{{u.cidade}}</td>
<td><a href="#/unidade-editar/{{u.idunidade}}">editar</a></td>
</tr>
</table>
</div>
</div>
</div>
Controller:
app.controller("UnidadeEditarCtrl", ['$scope', '$http', '$window', '$location', '$rootScope', '$routeParams', function ($scope, $http, $location, $rootScope, $routeParams) {
$scope.idempresa = localStorage.getItem('domanda_idempresa');
$scope.empresa = localStorage.getItem('domanda_empresa');
var getUnit = function(){
var idunidade = $routeParams.idunidade;
console.log('idunidade ' + idunidade)
}
getUnit();
Hi Leonardo. No, I did not make this change or confusion. But it worked again, I gave a "command + R" and it worked. Thanks
– GustavoSevero
Still it is wrong the snippet that you put here (may have been typo or something). But the string array for injection has these arguments in the following order
['$scope', '$http', '$window', '$location', '$rootScope', '$routeParams']
whereas your controller’s function has the followingfunction ($scope, $http, $location, $rootScope, $routeParams)
. Saw that the$window
in his role?– Leonardo Fachini Martins
Does it make a difference? The order and lack of $window?
– GustavoSevero
Yes, the order and quantity of items that Voce reports in the Array should be the same in its function. Angularjs uses this array of strings to search within it where these dependencies are. After it finds them it takes its function (controller) and calls it passing all the dependencies in the order it was informed. This is why it is important to keep the order Voce reports in the dependency array and the arguments of its function/controller.
– Leonardo Fachini Martins
Thanks for the information Leonardo!
– GustavoSevero