Passing data to mdDialog Passing data to mdDialog angularjs angularjs

Passing data to mdDialog


This guy always has the right answer: https://github.com/angular/material/issues/455#issuecomment-59889129

In short:

$mdDialog.show({            locals:{dataToPass: $scope.parentScopeData},                            clickOutsideToClose: true,                            controllerAs: 'ctrl',                            templateUrl: 'quotation/edit/',//+edit_id,            controller: mdDialogCtrl,        });var mdDialogCtrl = function ($scope, dataToPass) {     $scope.mdDialogData = dataToPass  }

Pass the variable using the locals attribute in the passing object. These values will be injected into the controller not the $scope. Also passing the entire $scope of the parent might not be such a good idea as it defeats the isolated scope paradigm.


HTML

<md-button ng-click='vmInter.showDialog($event,_dataToPass)'><i class="fa fa-custom-edit" aria-hidden="true"></i></md-button>

Js

    function _showSiebelDialog(event,_dataToPass) {        $mdDialog.show({                locals:{dataToPass: _dataToPass}, //here where we pass our data                controller: _DialogController,                controllerAs: 'vd',                templateUrl: 'contentComponents/prepare/views/Dialog.tmpl.html',                parent: angular.element(document.body),                targetEvent: event,                clickOutsideToClose: true            })            .then(                function(answer) {},                function() {                }            );    };function _DialogController($scope, $mdDialog,dataToPass) {console.log('>>>>>>> '+dataToPass);}


$scope.showPrompt = function(yourObject) {$mdDialog.show({    templateUrl: 'app/views/your-dialog.tpl.html',    locals: {        callback: $scope.yourFunction // create the function  $scope.yourFunction = function (yourVariable) {    },    controller:  function ($scope, $mdDialog, callback) {        $scope.dialog.title = 'Your title';        $scope.dialog.abort = function () {            $mdDialog.hide();        };        $scope.dialog.hide = function () {            if ($scope.Dialog.$valid){                $mdDialog.hide();                callback($scope.yourReturnValue, likes the return of input field);            }        };    },    controllerAs: 'dialog',    bindToController: true,    clickOutsideToClose: true,    escapeToClose: true});

};