将数据传递给 mdDialog [英] Passing data to mdDialog

查看:40
本文介绍了将数据传递给 mdDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


主列表页面有编辑按钮.这将打开已编辑行的详细信息.
Way-1: 现在,如果我设置ctrl.parent.q_details.client_location",它会与父列表控制器绑定,并且它作为 2 路绑定工作并自动更改编辑框中的值变化,这不是这里的要求.
这里只是我想在输入框中显示并允许编辑值.不想在父控制器中进行更改.

► 以下是父控制器中调用 mdDialog 的代码

$mdDialog.show({当地人:{父:$scope},clickOutsideToClose: 真,控制器为:'ctrl',templateUrl: 'quotation/edit/',//+edit_id,控制器:函数(){ this.parent = $scope;},});

► 以下是弹出 mdDialog 的代码.

<div ng-app="inputBasicDemo" ng-controller="deliverController" layout="column"><form name="" class="internal_note_cont"><md-content class="md-padding"><md-input-container class="md-input-has-value" flex><label>客户名称</label><输入 ng-model="qe.client_name" 需要 ></md-input-container><md-input-container flex><label>客户端位置</label><输入需要的ng-model="ctrl.parent.q_details.client_location"></md-input-container></md-content></表单><div>

<input type="" required ng-model="ctrl.parent.q_details.recid"></md-dialog>



方式2:第二种方式是直接从数据库发送值,而不绑定到对话控制器(deliverController)的ng-model.

]).controller("deliverController", ["$scope", "$filter","$http","$route","$window","$mdDialog",函数($scope,$filter,$http,$route,$window,$mdDialog){$scope.qe.client_name = '12345';//只是为了测试.}

这是 undefine $scope.qe 的错误.

所以最终,我无法将数据发送到 mdDialogue 并显示它们并允许以正常方式编辑它们.请任何有经验的有角的人帮助我.我是角度的新手.2 天以来,我一直在尝试不同的方法.

解决方案

这家伙总有正确答案:https://github.com/angular/material/issues/455#issuecomment-59889129

简而言之:

$mdDialog.show({当地人:{dataToPass:$scope.parentScopeData},clickOutsideToClose: 真,控制器为:'ctrl',templateUrl: 'quotation/edit/',//+edit_id,控制器:mdDialogCtrl,});var mdDialogCtrl = 函数($scope,dataToPass){$scope.mdDialogData = dataToPass}

使用传递对象中的 locals 属性传递变量.这些值将被注入控制器而不是 $scope.同样传递父级的整个 $scope 可能不是一个好主意,因为它破坏了隔离范围范式.


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 with parent listing controller and it works as 2-way binding and automatically changes the values as in the edit box changes, Which is not requirement here.
Here just I want to display and allow edit values in inputbox. Not want to get changed in parent controller.

► Following is the code in parent controller to call mdDialog

$mdDialog.show({
                locals:{parent: $scope},                
                clickOutsideToClose: true,                
                controllerAs: 'ctrl',                
                templateUrl: 'quotation/edit/',//+edit_id,
                controller: function () { this.parent = $scope; },
            });

► Following is code of the popup mdDialog.

<md-dialog aria-label="">
    <div ng-app="inputBasicDemo" ng-controller="deliverController" layout="column">
        <form name="" class="internal_note_cont">           
            <md-content class="md-padding">             
                <md-input-container class="md-input-has-value" flex>
                    <label>Client Name</label>
                    <input ng-model="qe.client_name" required >
                </md-input-container>
                <md-input-container flex>
                    <label>Client Location</label>
                    <input required ng-model="ctrl.parent.q_details.client_location">
                </md-input-container>                   
            </md-content>
        </form>
        <div>           
        </div>
    </div>
    <input type="" required ng-model="ctrl.parent.q_details.recid">  
</md-dialog>



Way2: second way is sending the value directly from DB without binding to ng-model of Dialog controller(deliverController).

]).controller("deliverController", ["$scope", "$filter","$http","$route","$window","$mdDialog",
    function ($scope, $filter,$http,$route,$window,$mdDialog) {
        $scope.qe.client_name = '12345'; // just to test.        
    }

This is giving error of undefine $scope.qe .

So ultimately, I am not able to send data to mdDialogue and display them and allow edit them as normal way. Please anyone experienced angular guy help me. I am new to angular. I am trying different ways since 2 days.

解决方案

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.

这篇关于将数据传递给 mdDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆