-2
I’m riding a controller
where one of the features is to take a data in the bank through your id. However, nothing appears in the console when I put this
Code that displays countries on the screen
<table width="200">
<tr>
<td><b>País</b></td>
<td><b>Sala</b></td>
</tr>
<tr ng-repeat="pais in paises">
<td>{{pais.nome}}</td>
<td>{{pais.sala}}</td>
<td><a href="#/editarPais/{{pais.idPais}}">editar</a></td>
</tr>
</table>
Html code
<form>
<input type="hidden" ng-model="pais.idPais">
País <input type="text" ng-model="pais.nome">
Sala <input type="text" ng-model="pais.sala">
<button ng-click="atualizarPais(pais)">Atualizar</button><br>
</form>
Acute code
app.controller("PaisesController", function ($scope, $http, $routeParams, $state) {
var carregaPaises = function () {
$http.get("admin/php/pegaPaises.php").success(function (data){
//console.log(data);
$scope.paises = data;
});
};
$scope.adicionaPais = function (pais) {
$http.post("admin/php/adicionaPais.php", pais).then(function (data){
//console.log(data);
carregaPaises();
})
};
var carregaPais = function (pais) {
console.log($routeParams.pais);
};
carregaPaises();
carregaPais();
});
Config code:
var app = angular.module("vc", ["ui.router", "ngRoute"]);
.state("paises", {
url: "/paises",
controller: "PaisesController",
templateUrl: "admin/views/paises.html"
})
.state("editarPais", {
url: "/editarPais/:idPais",
controller: "editarPaisController",
templateUrl: "admin/views/editarPais.html"
})
How do I see the data that comes in the parameter?
Exactly Celso. Because I’ve used this in another code and it worked.
– GustavoSevero
It’s a bit confusing.. Where should this parameter come from? the URL or the form? Based on your previous questions, you’re using
ui-router
right? And you just need to get the URL parameter, right?– celsomtrindade
Yes, it should come from the form and I’m using ui-router. I don’t know how it works at the angle, if the parameters come via url.
– GustavoSevero
If it comes from the form, then it has nothing to do with the URL parameter, is that it? You just need to get the ID that is in the Hidden input form?
– celsomtrindade
Exactly Celso. And disregard that ng-click "updatePais(parents)" button as it is not being used now. Now I want to load the data in the form for editing.
– GustavoSevero
So for now it is impossible to do this, because the data does not yet exist in the form, so we have no way to get the ID. Either you pass this variable through a global var, or coockie, or same url parameter.
– celsomtrindade
Celso, I had forgotten to put the screen codes that display the countries and their respective edit buttons with their ids. Take a look at the post statement. Sorry.
– GustavoSevero