0

I'm i bit stuck with function which is assigned to the $scope variable. need to wait until it's finished.

This is the function assigned to $scope variable:

$scope.ChooseHome = function() {
    ModalWindowService.openChooseHomeDialog($scope);
}

in ModalWindowService I have:

function openChooseHomeDialog($scope) {
    $scope.animationsEnabled = true;

    var modalInstance = $modal.open({
        animation: $scope.animationsEnabled,
        templateUrl: '/view/user/ChooseHomeDialog.html',
        controller: 'chooseHomeDialogController',
        windowClass: 'detail-modal-window'
    });
    modalInstance.result.then(function (CondoID) {
        $scope.choosenCondoID = CondoID;
    });
}

what I want to do is properly receive this variable '$scope.choosenCondoID' after I get it from modal in '$scope.ChooseHome' function and do some work with it.

smth like this options:

$scope.ChooseHome = function() {
    ModalWindowService.openChooseHomeDialog($scope).then(*do my stuff*); /
    ModalWindowService.openChooseHomeDialog($scope).success(*do my stuff*);
}

But it's not working, I'm getting errors like this:

'TypeError: (intermediate value).success is not a function'
1
  • 1
    As a sidenote...passing on your $scope to a service is a really bad idea. Commented Aug 17, 2015 at 14:36

2 Answers 2

2

Try this:

function openChooseHomeDialog($scope) {
    $scope.animationsEnabled = true;

    return $modal.open({
        animation: $scope.animationsEnabled,
        templateUrl: '/view/user/ChooseHomeDialog.html',
        controller: 'chooseHomeDialogController',
        windowClass: 'detail-modal-window'
    }).result;
}

$scope.ChooseHome = function() {
    ModalWindowService.openChooseHomeDialog($scope).then(*do my stuff*);
}

And...like I commented...passing on the $scope to your service is a bad idea. You should only use $scope in your controller to glue your data to the view. A service just has to do something or return something which you can use.

To complicate it a bit further..you might want to look into the controllerAs syntax as well to be future proof with your code ;)

Sign up to request clarification or add additional context in comments.

1 Comment

and don't send your $scope to the service :)
0

you must return your promise from openChooseHomeDialog function

...
return modalInstance.result.then(function (CondoID) {
  $scope.choosenCondoID = CondoID;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.