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

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

问题描述



主列表页面有编辑按钮。这将打开已编辑行的详细信息。

方式1:现在,如果我设置ctrl.parent.q_details.client_location,它将与父列表控制器绑定并且它可以正常工作作为双向绑定并自动更改编辑框中的值更改,这不是必需的。


这里我想显示并允许在inputbox中编辑值。不希望在父控制器中更改。


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.

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

► 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; },
            });

►以下是弹出式mdDialog的代码。

► 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:第二种方式是直接从DB发送值而不绑定到Dialog控制器的ng-model(deliverController)。



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.        
    }

这给出了undefine $ scope.qe的错误。



所以最终,我是无法将数据发送到mdDialogue并显示它们并允许以正常方式编辑它们。
请有经验的有角度的人帮助我。我是角色的新手。
我从2天开始尝试不同的方式。

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.

推荐答案

这家伙总能得到正确答案: h ttps://github.com/angular/material/issues/455#issuecomment-59889129

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

简而言之:

$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  
}

使用传递对象中的locals属性传递变量。这些值将注入控制器而不是$ scope 。传递父母的整个$范围可能不是一个好主意,因为它击败了孤立的范围范例。

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天全站免登陆