Javascript 如何使用AngularJs重定向到另一个包含对象数据的页面
我正在尝试将表单重定向到另一个页面,该页面是/customerActivation,其中包含从/getCustomerAccount路径获得的customer对象。我搜索了网上资源,尝试了很多建议,但都没有效果 所以我想问,是否有一种方法可以使用angular Js处理这个问题?这是我第一次处理这种情况 这是我的表单,它提交或调用控制器中的函数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
<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);
})