Home AngularJs - $emit wait a promise
Reply: 0

AngularJs - $emit wait a promise

Carlos Henrique Biazin Esteves
1#
Carlos Henrique Biazin Esteves Published in 2017-12-07 19:59:12Z

I'm using $rootScope.$emit to call a function inside another controller.

// Call
$rootScope.$emit('validarDadosBasicos');

// Declaration
$rootScope.$on('validarDadosBasicos', function(event) {            
    consistirDadosBasicos().then(result => {
         vm.factory.abasValidas.dadosBasicos = result;
    });
});

consistirDadosBasicos is a async function that return a promise.

After execute "validarDadosBasicos" I need to execute a lot of validations, but I need to wait this function return.

I'ts possible to return a promise inside $on? Are there a some way to force $emit to wait this return.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308133 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO