Angularjs data pass to Modal

Asked

Viewed 143 times

2

My problem is loading information into a modal. Controller Pai:

    App.controller('adminSolicitacoesCtrl', function($scope, $location, 
    $auth, solicitacaoAdminService, EmpresaService, $filter, $rootScope)
{   
$scope.solicitacao_modal = [];
$scope.init(function(){

//LISTA AS SOLICITAÇÕES DA EMPRESA
var listaSolicitacao = function()
{
    $scope.init(function(){});

    solicitacaoAdminService.listarSolicitacoes(function(response)
    {
        $scope.solicitacoes = response;
    }, 
    function(err){
        console.log(err);
        swal("Não foi possível carregar as solicitações", "Tente novamente mais tarde", "error");
    });

}
    $scope.verSolicitacao = function(id)
    {
        solicitacaoAdminService.versolicitacao(id, function(response)
        {
             $('#verSolicitacao').modal();
             $scope.solicitacao_modal = response;
             $rootScope.$broadcast('verSolicitacao', $scope.solicitacao_modal)
        }, function(err)
        {
            console.log(err);
            swal("Não foi possível carregar as solicitações", "Tente novamente mais tarde", "error");
        });
    };

    listaSolicitacao(); 
 });    

 });

Child controller:

App.controller('verSolicitacaoCtrl', function($scope, $location, $auth, 
solicitacaoAdminService, EmpresaService, $filter, $rootScope,)
{   
$scope.solicitacoes_recebe = []
$scope.init(function(){

    $scope.$on('verSolicitacao', function(solicitacao_recebe) {
    $scope.solicitacoes_recebe = $scope.solicitacao_modal;
    $scope.solicitacoes_recebe;
});

  });    

  });

html:

<div class="modal fade modal-padrao" tabindex="-1" role="dialog" id="verSolicitacao" style="z-index: 20000;" ng-controller="verSolicitacaoCtrl as Slct">
<div class="modal-dialog" role="document">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Solicitação</h4>
        </div>
        <div class="modal-body">
            <div class="row" style="margin-top:-30px">
                <div class="col-md-12">
                    <h3>O cliente {{Slct.solicitacao_modal.nome_empresa}} solicitou o seguinte: <b style="color:red">{{slct.solicitacoes.tipo_solicitacao}}</b></h3>
                    <hr>
                </div>
       ...

All data passing is being successfully performed by starting with the loading of the content on the basis of the selected id (that’s not the case), the passage through $broadcast to $on is also working and the child Scope receives the array with the information but I cannot display itThey were inside the modal. I’ve tried to use a single controller and several ways to call the variable that seemed plausible, but although the information is being passed to Scope inside the verSolicitacaoCtrl controller, I can’t display anything in the modal.

  • For communication between modal and other controllers I use the $rootScope, tried to use root Scope for this case?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.