Passing data to mdDialog

前端 未结 5 1523
盖世英雄少女心
盖世英雄少女心 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:24

    The ES6 TL;DR way

    Create a controller with scope variables on the fly

    let showDialog = (spaceApe) => {
        $mdDialog.show({
            templateUrl: 'dialog.template.html',
            controller: $scope => $scope.spaceApe = spaceApe
        })
    }
    

    Template

    Voilà, spaceApe can now be used in the dialog template

    <md-dialog>
        <md-dialog-content>
            <span> {{spaceApe | json}} </span>
        <md-dialog-content>
    <md-dialog>
    
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-31 14:27

    This worked for me:

            confirmNewData = function() {
            let self = this;
            this.$mdDialog.show({                
                templateUrl: '/dist/views/app/dialogConfirmAFEData.html',
                controllerAs: "ctrl",                                
                controller: $scope => $scope = { $mdDialog: self.$mdDialog, 
                                                 data: self.FMEData, 
                                                 cancel: function() { this.$mdDialog.cancel(); }, 
                                                 confirm: function() { this.$mdDialog.hide(); }  
                                               },
                clickOutsideToClose: false
            }).then(function() {
                // User Accepted!!
                console.log('You accepted!!!');
            }, function() {
                // User cancelled, don't do anything.
                console.log('You cancelled!!!');
            });
        };
    

    And in the view...

    <md-dialog aria-label="Start New AFE" style="min-width: 50%;">
        <md-toolbar>
          <div class="md-toolbar-tools">
            <h2>GIS Data...</h2>          
          </div>
        </md-toolbar>
        <md-dialog-content>
            <div layout="column" layout-padding>
                <li/>Lease: {{ ctrl.data.LEASE }}    
                <li/>Reservoir: {{ ctrl.data.RESERVOIR }}    
            </div>
        </md-dialog-content>
    
        <md-dialog-actions layout="row">
          <md-button class="md-button" ng-click="ctrl.cancel()">Cancel</md-button>
          <md-button class="md-button" ng-click="ctrl.confirm()">Yes</md-button>                
        </md-dialog-actions>
    

    0 讨论(0)
  • 2021-01-31 14:33
    $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
    });
    

    };

    0 讨论(0)
  • 2021-01-31 14:41

    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);
    }
    
    0 讨论(0)
提交回复
热议问题