returning uibmodal result to parent controller

TobyStack picture TobyStack · Dec 7, 2016 · Viewed 12.4k times · Source

so here is my modal JS:

The end goal of this piece of code is to print the object "submitVar" somewhere on the parent page, the object could be a string or a JSON. All the variables in questions are being chaned using ng-model in the HTML. I don't know how to pass this value back to the parent controller and need some help.

Currently the line console.log('submitting') runs, but i don't know where the submitVar result is placed. I'm planning to use this as as an editing window, so an object is passed in, then edited and passed back, changing the current value.

I'm using: https://angular-ui.github.io/bootstrap/ as a reference and cant find any other documentation on this.

Answer

Pankaj Parkar picture Pankaj Parkar · Dec 7, 2016

Inside result.then of modalInstance object you can get value returned while closing modalInstance

modalInstance.result.then(function(submitVar) {
    console.log("sumbited value inside parent controller", submitVar);
})