angularjsng-dialog

closing ngDialog in controller


i have two function , one for opening dialog and one for posting data to server and then close the dialog , the problem is i cant close dialog , here us the code

 vm.openCreateDialog = function () {

                 var Dialog = ngDialog.open({
                    template: 'user/create',
                    className: 'ngdialog-theme-default'
                })
            }
vm.createUser = function () {
           DataService.createUser(vm.user).then(function (response) {
                $log.log('promise returned successfully')
                Dialog.close();

            }).catch(function (e) {
                $log.log('catch registration error')

            });
}

Solution

  • ngDialog.open() return an object with id , the id is id of dialog box , I use it to close the dialog box , here is working code if anybody came to it

     vm.openCreateDialog = function () {
    
                     vm.Dialog = ngDialog.open({
                        template: 'user/create',
                        className: 'ngdialog-theme-default',
    
                     })
                     vm.dialogId = vm.Dialog.id;
                }
    

    and from another function I just used the id to close dialog

      ngDialog.close(vm.dialogId)