Javascript 在路线angularjs/expressjs之间传递数据

Javascript 在路线angularjs/expressjs之间传递数据,javascript,angularjs,forms,express,Javascript,Angularjs,Forms,Express,我有一个表单,当我提交它时,另一个表单显示为单选按钮,这些按钮是其他数据。我选择一个并提交它。我希望数据显示在另一个页面中,但它不显示我所做的任何事情 所以这里有一个/form路由,我希望在上次提交之后,在/confirmation路由上重定向我的数据 贝娄是我在angularjs中的formController .controller('formController', ['$scope', '$http', '$location', function($scope, $http, $loca

我有一个表单,当我提交它时,另一个表单显示为单选按钮,这些按钮是其他数据。我选择一个并提交它。我希望数据显示在另一个页面中,但它不显示我所做的任何事情

所以这里有一个/form路由,我希望在上次提交之后,在/confirmation路由上重定向我的数据

贝娄是我在angularjs中的formController

.controller('formController', ['$scope', '$http', '$location', function($scope, $http, $location) {
    $scope.pageClass = 'form';
    $scope.firstName = '';
    $scope.lastName = '';
    $scope.email = '';
    $scope.departure = '';
    $scope.destination = '';
    $scope.submitFirstForm = function() {
        $http.post('/form', {
            firstName: $scope.firstName,
            lastName: $scope.lastName,
            email: $scope.email,
            departure: $scope.departure,
            destination: $scope.destination,
        }).then(function(res) {
            $scope.response = res.data;
            });
        }

    $scope.submitConfirmationForm = function(flight){

        $http.post('/confirmation', {
            departure: $scope.departure,
            destination: $scope.destination
        }).then(function(res) {
            $scope.otherResponse = res.data;
            $location.path("/confirmation");
            });

    };
}]);
以下是我的特快专递功能,仅用于/确认路线

    app.post("/confirmation",function(req,res)
{
    var departure=req.body.departure;
    var destination=req.body.destination;

    otherResponse = {
        "confirmation": [{
            "departure": departure,
            "destination": destination,
            "msg": "MSG OK",
        }]
    };

    res.json(otherResponse);
});
 <pre>
    {{otherResponse | json}}
</pre>
最后,在my confirmation.html下吼,看看我的json OtherResponse发生了什么事

    app.post("/confirmation",function(req,res)
{
    var departure=req.body.departure;
    var destination=req.body.destination;

    otherResponse = {
        "confirmation": [{
            "departure": departure,
            "destination": destination,
            "msg": "MSG OK",
        }]
    };

    res.json(otherResponse);
});
 <pre>
    {{otherResponse | json}}
</pre>

{{otherResponse}json}

如果没有传递“值”,则需要执行以下操作:

$location.path('/confirm/').search({param:'otherResponse'})

$location方法是可链接的

这将产生:

/确认/?参数=其他响应

检查文档是否有错误