I cannot pass Objects between controller using Brodcast and Angularjs On

Asked

Viewed 23 times

1

//Tenho uma injeção de dependência aqui
 PedidoController.$inject = ['$rootScope', '$state','ModalService', NotificationService','PedidoService', 'BoletoService'];

// Construtor do meu controller
function PedidoController($rootScope,$state,ModalService, NotificationService, PedidoService,BoletoService)

//To passando um objeto para outro controller
function listarBoletos(pedido) { vm.boletos = pedido.boletos; $rootScope.$broadcast('BoletosSelecionados',pedido.boletos); $state.go('boleto');}

//Injection controller receptor
BoletoController.$inject = ['$scope','BoletoService'];

// Construtor Controller receptor
function BoletoController( $scope,BoletoService)

//Recepção do Objeto
$scope.$on('BoletosSelecionados',function (event, OEvent) { vm.boletos=OEvent; console.log(OEvent);
  • There’s a little mistake there on the first line: 'NotificationService' does not have the initial single quotes.

  • Since the two controllers have an injection of Boletoservice why don’t you store the orders in a variable within the Boletoservice? Services Singleton (an instance for the entire application) can be used to share variables. I believe you’re better at performance issues by eliminating the need to keep monitoring events.

  • @Onosendai I took a look at the code and it is with the quotation mark, vlw.

  • @Sorack not in my case I’m using the inject controller because of legacy code.

  • @arthurcláudio It means that your code is different in relation to what you posted in the question?

  • Thank you for answering, man I’m new in angular JS , how would I do that? This code is legacy there ever saw.

  • @Felipepaetzold some idea of how to fix it?

  • @arthurcláudio puts the complete code of the controllers so I can help better

  • @Felipepaetzold was just trying to help

Show 4 more comments
No answers

Browser other questions tagged

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