Есть ли способ передать переменную $ scope.variable в $ http.post? проблема # в полезной нагрузке моя переменная не публикуется - PullRequest
0 голосов
/ 29 апреля 2018

В HTML у меня есть несколько полей регистрации клиентов

<input type="text" ng-model="customer.fname">
<input type="text" ng-model="customer.lname">
<input type="text" ng-model="customer.username">

Код моего углового контроллера

    var customerInformation = $scope.customer;

    customerInformation = JSON.stringify($scope.customer);
    $http({
        method: 'POST',
        url: 'person/registrationCustomer',
        data: customerInformation,
        timeout: 4000
    })
        .then(function (success) {

        }, function (error) {


        });

Ответы [ 2 ]

0 голосов
/ 29 апреля 2018

Попробуйте это:

var customerInformation = $scope.customer;

$http.post('person/registrationCustomer',customerInformation)
    .then(function (success) {

    }, function (error) {


    });
0 голосов
/ 29 апреля 2018

Да, ваши данные должны быть сопоставлены с объектом, посмотрите:

var dataObj = {
    customerInformations : $scope.customer;
};  


$http({
    method: 'POST',
    url: 'person/registrationCustomer',
    data: dataObj,
    timeout: 4000
})
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...