0

i have modal box. I want submit form, show success message, and after 3 sec, close modal box. Here is my ctrl

            $http.post(serviceBase + 'aaaa', data, config)
                .success(function (data, status, headers, config) {
                    $scope.PostDataResponse = data;
                    $scope.messages = ['Success'];

                }, startTimer())
                .error(function (data, status, header, config) {
                    var messages = [];
                    angular.forEach(data.errors, function (value, key) {
                        $scope.ResponseDetails = "Data: " + data +
                                "<hr />status: " + status +
                                "<hr />headers: " + header +
                                "<hr />config: " + config;
                        messages.push('Error! ' + key + ' is not correct');

                    });
                    $scope.messages = messages;
                });
                // expose dependencies on this


};
var startTimer = function () {
    var timer = $timeout(function () {
        $timeout.cancel(timer);
        $location.path('/klupe');
              }, 3000);

};

But timer not working, if i console.log $location.path, it's ok, but function startTimer() is not calling. Thnx

1 Answer 1

1

Put the function call inside the success block, not as a second paramter

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

7 Comments

thnx, but still the same. I got success message, but timer is not started, not redirect me
Try removing cancel timer, $timeout.cancel(timer); this should ideally prevent the task from running
thanke you this working, and i also change $location.path to $state.go. But now i have another problem. How to close modal box with this timer? here is from my template <button type="button" class="btn btn-default" ng-click="$dimiss()" data-dismiss="modal"></button>
I dont get your requirement
Call the dismiss function before the path change
|

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.