I am presenting to you a problem I can not solve despite much effort.
First, I present a dialog to insert a password, and then immediately turns to the controller and executes an action on the server.
What I want to do is get the answer and return it to Callback where the dialog is announced.
look at the this :
function passwordDialog(packagePath,folderUnzippingTo) {
        return $q(function(resolve, reject) {
            $mdDialog.show({
                controller: passwordDialogController,
                controllerAs: '$ctrl',
                locals: {
                    packagePath: packagePath,
                    folderUnzippingTo: folderUnzippingTo,
                },
                template:
                `<md-dialog  aria-label="Enter Password" layout="column">
                        <md-content md-theme="docs-dark" layout-padding>
                            <md-input-container class="md-block">
                                <label>Password</label>
                                <input type="password" ng-model="password"></input>
                            </md-input-container>
                        </md-content>
                        <md-dialog-actions>
                            <md-button ng-click="sendData(packagePath,folderUnzippingTo)" class="md-raised md-primary">
                            OK
                            </md-button>
                            <md-button ng-click="close()" class="md-primary">
                            Cancel
                            </md-button>
                        </md-dialog-actions>
                    </md-dialog>`,
                // clickOutsideToClose: true,
                parent: $rootScope.parentEl,
            })
                .then(
                function (success) {
                    resolve(success);
                },
                function (err) {
                    console.log("Password Dialog is not working");
                    reject(err);
                }
                );
        });
    }
I want to get a respond from the server and pass it through a promise to here.
my controller:
function passwordDialogController($scope, $mdDialog, packagePath,folderUnzippingTo) {
            return $q(function(resolve, reject) {
                $scope.packagePath = packagePath;
                $scope.folderUnzippingTo = folderUnzippingTo;
                $scope.close = function () {
                    $mdDialog.cancel();
                }
                $scope.sendData = function (packagePath, folderUnzippingTo) {
                    $mdDialog.hide(
                        {
                            "password": $scope.password,
                        });
                    $http.post(SERVER_PATH + '/openPassword', { filePath: packagePath, password: $scope.password,outputFolder: DataFolder.DATA_FOLDER + _PACKAGES_FOLDER + folderUnzippingTo})
                        .then(
                        function (success) {
                            console.log("The password is right");
                            resolve(success);
                        },
                        function (err) {
                            console.log("The password is wrong");
                            console.log("Password controller is not working");
                            reject(err);
                        });
                }
            });
        }
As I explained, after receiving a reply from the server I would like to return a callback to the passwordDialog function but because I did not build the code well I always got success here :
              .then(
                function (success) {
                    resolve(success);
                },
some help?
 
    