TypeError: Cannot read property 'then' of undefined

I think I just need another pair of eyes on this, because I can't get what I'm missing here.

   $scope.checkout = function (form) {
        //some code here

        function checkoutErrorHandler(error) {
          //some code here
        }

        function displaySuccessMessage() {
            $scope.success = true;
            cartService.emptyCart();    
        }

        checkoutService.makePayment($scope.payment).then(function (i) {

            //some code here
            checkoutService.buyProducts($scope.payment, products, i).then(function () {
                    displaySuccessMessage().then(function(){
                        $scope.payment = {}; // clear checkout form
                        $scope.form.reset();
                    });
                    return displaySuccessMessage;
                },
                checkoutErrorHandler
            );
        }, checkoutErrorHandler);
    };

I get "Cannot read property 'then' of undefined" when I call displaySuccessMessage. I've tried refactoring several different ways but cannot get it to work. Does anyone see my mistake?


Your displaySuccessMessage does not return a promise. In fact, it doesn't return anything.

Assuming that cartService.emptyCart() returns a promise, you can modify displaySuccessMessage like this and it should work just fine:

    function displaySuccessMessage() {
        $scope.success = true;
        return cartService.emptyCart();
    }
链接地址: http://www.djcxy.com/p/22930.html

上一篇: Apache Storm可以互相沟通吗?

下一篇: TypeError:无法读取未定义的属性'then'