0

I am working on Angularjs application, I have a requirement where I have to send hidden variables to a third party application.

Value of these hidden variables should come from database.

I am using following code to dynamically create hidden variables.

<input type="hidden" ng-repeat="hdnvar in models.MyModel.templateVariables" name="{{hdnvar.Key}}" id="{{hdnvar.Key}}" value="{{hdnvar.Value}}" />

Follwing function is called when user clicks on submit button

 $scope.getDetailsForTP = function () {
        $scope.models.MyModel.templateVariables = {};
        $http({
            url: "http://localhost:11149/MyService.svc/TemplateVariable",
            dataType: "json",
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            }
        }).then(function successCallback(response) {
            if (response.status == 200) {
                $scope.models.MyModel.templateVariables = response.data;
                $scope.submitForm();
            }
            else {
                alert('Error occurred in fetching template variable data');
            }
        }, function errorCallback(response) {
            //do something
        });
    };

    $scope.submitForm = function () {
        document.getElementById("apirequest").submit();
    };

Hidden variables are rendered correctly on a page but when i check fiddler I can't find the hidden variables submitted.

Can someone please help?

2
  • 1
    Why are you submitting your form. You can post your data using $http service and pass your modal data (array) in data field of request. Commented Sep 21, 2016 at 12:03
  • Thanks for your comment. Could you please provide an example to do that? Commented Sep 23, 2016 at 5:18

1 Answer 1

1

you are submitting the form as soon as you updated templateVariables. it takes some time to render html elements.

so you need to submit the form after some delay.

$scope.models.MyModel.templateVariables = response.data;
$timeout($scope.submitForm, 1000)  // submit form after 1 second
Sign up to request clarification or add additional context in comments.

1 Comment

Adding a delay will solve this. But it might take more than a second to render HTML elements. Is there any way I can submit the form only after rendering of HTML elements?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.