Я пытаюсь перенаправить мою форму на другую страницу, которая является / customerActivation с объектом customer, полученным из маршрута / getCustomerAccount. Я искал в Интернете источники и перепробовал много предложений, но ни одно из них не работает.
Поэтому я хочу спросить, есть ли способ справиться с этим с помощью 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);
});