AngularJS passing data back from mdDialog to parent controller -


i have little angularjs application making use of $mddialog pop html page has 1 text input on it

i want able return value user types input parent scope. i'm unsure how this.

this have far

$scope.shownewteamdialog = function () {    $mddialog.show({        controller: newteamdialogcontroller,        templateurl: 'newteam.html',        locals: { newteamname: $scope.newteamname },        parent: angular.element(document.body)    }) };  function newteamdialogcontroller($scope, $mddialog, newteamname) {        $scope.closedialog = function(newteamname) {            // before closing want set $scope.newteamname whatever user typed in text on dialog pop            $mddialog.hide();       }   } 

any appreciated

while wouldn't right before dialog closed, using .then part of dialog.show promise. here codepen using 1 of ngmaterial examples modify variable on close: https://codepen.io/mckenzielong/pen/vebrge. basically, this:

$scope.shownewteamdialog = function () {    $mddialog.show({        controller: newteamdialogcontroller,        templateurl: 'newteam.html',        locals: { newteamname: $scope.newteamname },        parent: angular.element(document.body)    })    .then((newteamname) => {      $scope.newteamname = newteamname;    }) };  function newteamdialogcontroller($scope, $mddialog, newteamname) {      $scope.closedialog = function(newteamname) {     $mddialog.hide(newteamname);   }   } 

alternatively little more ugly, , share scope this: https://codepen.io/mckenzielong/pen/zeoare. 1 downside code become confusing quickly. this:

$scope.shownewteamdialog = function () {    $mddialog.show({        controller: newteamdialogcontroller,        templateurl: 'newteam.html',        scope: $scope.newteamname,        parent: angular.element(document.body)    })    .then(() => {     }) };  function newteamdialogcontroller($scope, $mddialog) {      $scope.closedialog = function(newteamname) {     $scope.newteamname = newteamname     $mddialog.hide();   }   } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -