0

I have a simple form:

<form ng-cloak class="form-horizontal" name="regForm" ng-submit="submit()" novalidate>
<input type="text" class="form-control" id="pociFirstName" placeholder="First Name" name="pociFirstName" ng-model="poc.firstName" ng-required="true" ng-class="{red: regForm.pociFirstName.$invalid && (regForm.$submitted || regForm.pociFirstName.$touched)}" />
<input type="text" class="form-control" id="pociLastName" placeholder="Last Name" name="pociLastName" ng-model="poc.lastName" ng-required="true" ng-class="{red: regForm.pociLastName.$invalid && (regForm.$submitted || regForm.pociLastName.$touched)}" />
<input type="text" class="form-control" cc-number cc-eager-type cc-type="cardType" id="ccNum" placeholder="Card Number" name="ccNum" ng-model="card.number" ng-required="true" ng-class="{red: regForm.ccNum.$invalid && (regForm.$submitted || regForm.ccNum.$touched)}" ng-init="card.number=''"/>

....

<button class="btn btn-primary btn-payment" type="submit">Submit</button>   

</form>

then I have started part for the controller

$scope.regForm = {};
$scope.poc = {};
$scope.card = {};

$scope.submit = function () {

    console.log("Form submited");

    $scope.regForm = regForm;
    $scope.poc = regForm.poc;
    $scope.card = regForm.card;

    console.log("data: " + $scope.poc);
}

but after form submitting I'm not able to get data from the form - it came as undefinied.

Kind of simple thing to do but I have no idea where I have a mistake.

0

1 Answer 1

2

It should be like this. you can access to ng-model value by $scope. so for access ng-model="poc.firstName" and ng-model="poc.lastName" just use $scope.poc and for access ng-model="card.number" use $scope.card.

$scope.submit = function () {
  console.log("Form submited");
  console.log("data: " + $scope.poc);
}
Sign up to request clarification or add additional context in comments.

1 Comment

And this is it. Thanks!

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.