Passing data to mdDialog

前端 未结 5 1522
盖世英雄少女心
盖世英雄少女心 2021-01-31 13:37


Main listing page has edit button. Which opens details of the edited row.
Way-1: Now, if I set \"ctrl.parent.q_details.client_location\" it is bind wit

5条回答
  •  后悔当初
    2021-01-31 14:26

    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.

提交回复
热议问题