Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用AngularJs重定向到另一个包含对象数据的页面_Javascript_Node.js_Angularjs_Routes - Fatal编程技术网

Javascript 如何使用AngularJs重定向到另一个包含对象数据的页面

Javascript 如何使用AngularJs重定向到另一个包含对象数据的页面,javascript,node.js,angularjs,routes,Javascript,Node.js,Angularjs,Routes,我正在尝试将表单重定向到另一个页面,该页面是/customerActivation,其中包含从/getCustomerAccount路径获得的customer对象。我搜索了网上资源,尝试了很多建议,但都没有效果 所以我想问,是否有一种方法可以使用angular Js处理这个问题?这是我第一次处理这种情况 这是我的表单,它提交或调用控制器中的函数 <div ng-controller="CustomerController"> <h3> Please Enter you

我正在尝试将表单重定向到另一个页面,该页面是/customerActivation,其中包含从/getCustomerAccount路径获得的customer对象。我搜索了网上资源,尝试了很多建议,但都没有效果

所以我想问,是否有一种方法可以使用angular Js处理这个问题?这是我第一次处理这种情况

这是我的表单,它提交或调用控制器中的函数

<div ng-controller="CustomerController">
  <h3> Please Enter your customer loyalty card number</h3>
  <form ng-submit="activateAccount()">
       <div class="form-group">
            <input type="text" class="form-control" id="formCard"
                   ng-model="nbcard" placeholder="Card number" required>
       </div>

       <button type="submit" class="btn btn-info btn-lg btn-block btn-trans ">
         Activate my account
       </button>
  </form>
</div>
customerManageAPP = angular.module('customerMngAPP', []);

customerManageAPP.controller('CustomerController',  function($scope, $http) {

    let URL_ACT_ACCOUNT = `http://localhost:${port}/getCustomerAccount`;

    $scope.activateAccount = function() {
        $http.get(URL_ACT_ACCOUNT + `?cardNumber=${$scope.nbcard}`)
            .then(function (response) {
                $scope.customerAccount =  response.data;
                $location.path('/customerActivation/' + $scope.customerAccount.firstname + $scope.customerAccount.lastname);
            });
    };
});
我的路由文件中有这个

router.get('/customerActivation', function(req, res) {
    res.setHeader('Content-Type', 'text/html');
    res.sendFile( __dirname + '/views' + '/customerActivation.html');
});

router.get('/getCustomerAccount', async (req, res) => {
    const { cardNumber } = req.query;

    const response = await Customers.find({"nb_card": cardNumber});

    res.json(response);

});

通常,使用客户端路由器解析url:

使用ngRoute:

有关详细信息,请参阅

angular.module("app",["ngRoute"])
.config(function($routeProvider) {
    $routeProvider.when({
        url: "/customerActivation/:customerId",
        templateUrl: "views/customerActivation.html",
        controller: "ActivationController"
    })
})
.controller("ActivationController", function($scope, $routeParams) {
    console.log("customerId", $routeParams.customerId);
})