控制器中的 ngDialog 范围作为场景

ngDialog scope in controller as scenario

我有媒体列表,当我点击一个项目我想打开 ngDialog 并将模型传递给 ngDialog 时,我已经阅读了文档和博客,但它们都使用 $scope 来传递模型或数据,而不是控制器作为 (虚拟机)。我如何使用 vm 将数据传递给 ngDialog 控制器以及如何在 vm(Controller as) case

中从 ngDiloag 控制器调用父 vm($parent.$scope)

这是我的代码(简化版)

(function () {
    'use strict';
    angular
        .module('app.media')
        .controller('mediaController', Controller);

    Controller.$inject = ['$filter', 'ngTableParams', '$rootScope', '$http', '$log', '$uibModal', 'ngDialog', 'toaster', 'mediaDataService'];

    function Controller($filter, ngTableParams, $rootScope, $http, $log, $uibModal, ngDialog, toaster, mediaDataService) {
        var vm = this;

        vm.media = {};


        activate();



        function activate() {

            vm.updateMedia = function () {
                mediaDataService.updateMedia(vm.media).then(function (res) {
                    toaster.pop('success', 'ویرایش فایل با موفقیت انجام شد', 'ویرایش فایل')
                })
            }


            vm.openUpdateDialog = function (media) {
                //i want to use vm.media in opening dialog
                vm.media = media;
                ngDialog.open({
                    template: 'media/edit'
                    , className: 'ngdialog-theme-default'
                    , controller: 'updateMediaController',

                    //i had used data to pass data to new controller and used ngDialogData in my opening template to access media , 
                    //the probelm with this case is i cant access parrent controller(the controller that is openin dialog) from DngDialog
                    //opened Controller(because i want to run parrent controller  updateMedia function  when user click update in opened dialog)
                    //**commented out - not usefull **//    
                    //data:media
                })
            }

        }
    }
})();

有什么建议吗? 谢谢

试试这个:

If you use a controller with separate $scope service this object will be passed to the $scope.$parent param: see this for more information

 ngDialog.open({
                template: 'media/edit',
                 className: 'ngdialog-theme-default',
                 controller: 'updateMediaController',
                 scope:$scope
            })