4
Guys the problem, in a general way, is that I can’t take information received in a controller and apply it in my html, when I try instead of printing the variable on the screen becomes empty, when I give a console.log in my scope, the information is there available, but they’re not put on the screen when I need them.
So, I have a user search very similar to the facebook.
<form class="navbar-form navbar-left" role="search" ng-controller="pesquisas">
<div class="form-group">
<input type="text" ng-keyup="search()" ng-keydown="search()" ng-model = "pesquisa.nome_usuario" class="form-control pesquisar_input" placeholder="Pesquisar">
</div>
<!-- <button type="submit" class="btn btn-default">Pesquisar</button> -->
<div class = "resultado_pesquisa" ng-show="resultado>0">
<ul>
<li class = "linha_usuario_pesquisa"ng-repeat = "usuario in usuarios " data-refresh-list data-toggle="modal" href='#avaliacao' ng-click="dados_usuario(usuario)" ng-controller="avaliacao" >
<div class = "imagem_perfil_masculino pull-left" ng-show="usuario.sexo_usuario==1">
<span class="glyphicon glyphicon glyphicon-user usuario_masculino" ></span>
</div>
<div class = "imagem_perfil_feminino pull-left" ng-show="usuario.sexo_usuario==0">
<span class="glyphicon glyphicon glyphicon-user usuario_masculino" ></span>
</div>
<span class = "nome_linha_usuario pull-left" >{{usuario.nome_usuario}}</span>
</li>
</ul>
</div>
</form>
The controller that performs the search is this.
$scope.search = function(){
if($scope.pesquisa.nome_usuario.length >0){
$http.post('usuarios/consult_user',$scope.pesquisa)
.success(function(data){
$scope.resultado = 1;
$scope.usuarios = data;
});
}
else{
$scope.resultado = 0;
$scope.usuarios = 0;
}
}
Where my list starts I can click on it, and send the user data through an ng-click, my controller that receives this information is as follows.
app.controller('avaliacao', function ($scope, $http) {
$scope.dados = {};
$scope.dados_usuario = function (usuario) {
$scope.dados = usuario;
});
});
At the same time this function is requested the following modal is opened, where the idea is to insert all rescued user information.
<div class="modal fade " id="avaliacao" data-backdrop="static" ng-controller="avaliacao">
<div class="modal-dialog full-screen">
<div class="modal-content" >
<div class="modal-body">
<div class="navbar navbar-fixed-top nav-interna">
<div class = "imagem_perfil_masculino_interno pull-left" >
<span class="glyphicon glyphicon glyphicon-user usuario_masculino" ></span>
</div>
<span class="pull-left nome_aluno_interno" ><h4 >{{dados.nome_usuario}}</h4></span>
<button type="button" class="close pull-right" data-dismiss="modal" aria-hidden="true">×</button>
</div>
</div>
</div>
</div>
</div>
Please put all the code I believe it’s easier to help you like this !!!
– user6026
Yes, place the html otherwise it is impossible to decipher. But right off the bat it is very strange a function tied to an ng-click "receive" data. Generally, the data is linked to the variables placed in the form via ng-model.
– Dema
Post your html code, it will be easier to find the error.
– user7446
Your code has several "smells" that you are mixing the balls in the jQuery/Bootstrap way of doing things with the Angular way. A clear problem is that you should not have the same controller for 2 different views. I would advise you to take a look at the Angular UI Bootstrap or Angularstrap project and see an alternative way more "Angulariana" to do what you want to do.
– Dema
Got it, thanks for the suggestion!
– user7443
@Dema can explain what the smells are? As for a controller for a view, this is not a "Angularian standard".
– Bertrand
@Bertrand In fact, Angular encourages you to break down your page into several smaller components and that each component of it has an associated, inter-connected controller by the Scope inheritance mechanism. But reusing the same controller for 2 different views is something unusual, which usually leads to a more complex controller than it should be.
– Dema