如何访问 $mdDialog 模态控制器中的父控制器数据

How to access parent controller data in $mdDialog modal controller

Angularjs $mdDialog 在传递此信息时未打开模式。为什么?

我正在尝试访问子控制器中的父控制器数据。数据正在传递,但模式未打开。当我打印它显示的响应时

Cannot read property 'createDocumentFragment' of undefined

var ctrl = this;
ctrl.add_user_popup = function(data){

    $mdDialog.show({
        templateUrl: 'userManagement/addUserPopup.html',
        controller: 'addUserPopup_controller',
        controllerAs: 'umpctrl',
        clickOutsideToClose: true,
        dataToEdit: data,
        escapeToClose: true,
        parent: ctrl  //When I comment this line modal opens
    }).then(function(response){
        console.log('add_user_popup success',response);
    }, function(res){
        console.log('add_user_popup failed',response);
    })
}

I want to access parent controller data in the modal controller.

var ctrl = this;
ctrl.add_user_popup = function(data){
    return $mdDialog.show({
        templateUrl: 'userManagement/addUserPopup.html',
        controller: 'addUserPopup_controller',
        controllerAs: 'umpctrl',
        clickOutsideToClose: true,
        ̶d̶a̶t̶a̶T̶o̶E̶d̶i̶t̶:̶ ̶d̶a̶t̶a̶,̶
        locals: { dataToEdit: data },
        bindToController: true,
        escapeToClose: true,
        ̶p̶a̶r̶e̶n̶t̶:̶ ̶c̶t̶r̶l̶ ̶ ̶/̶/̶W̶h̶e̶n̶ ̶I̶ ̶c̶o̶m̶m̶e̶n̶t̶ ̶t̶h̶i̶s̶ ̶l̶i̶n̶e̶ ̶m̶o̶d̶a̶l̶ ̶o̶p̶e̶n̶s̶
    }).then(function(result){
        console.log('add_user_popup success',result);
        return result;
    }, function(reason){
        console.log('add_user_popup dismissed',reason);
        throw reason;
    })
}

使用对话框选项对象的 locals 属性。

来自文档:

  • locals - {object=}: An object containing key/value pairs. The keys will be used as names of values to inject into the controller. For example, locals: {three: 3} would inject three into the controller, with the value 3. If bindToController is true, they will be copied to the controller instead.
  • bindToController - bool: bind the locals to the controller, instead of passing them in.

有关详细信息,请参阅