0

In Angular JS are created inputs.

<input type="text">
<input type="text">

How I can to get values from each inputs and send to server?

I tried:

<input type="text" ng-model="typeInput">

But I get value only one field.

In server I am planning to get data format: $_POST['type'][0] = 'One value'; $_POST['type'][1] = 'Two value';

I mean, that I need send to server array of values. For example:

name="type[]" value="1"
name="type[]" value="2"
name="type[]" value="3"

So, in server I cando loop for check:

foreach($_POST['type'] as $val){
  //prepare
}
2
  • use that ng-model as $scope.typeInput while sending it Commented May 4, 2015 at 20:28
  • 1
    Specify your question clearly. It does not specify what do you want to achieve? Commented May 4, 2015 at 20:48

1 Answer 1

2

Using the ng-model binds it to the property of the same name in the $scope of the controller.

You would access it in your controller like so:

$scope.typeInput

Or you can access it in your HTML like so:

{{typeInput}}

To access both fields, you would need to give them both a different property name to bind to.

<input type="text" ng-model="firstName">
<input type="text" ng-model="lastName">
...
alert($scope.firstName);
alert($scope.lastName);

More complete info here: https://docs.angularjs.org/api/ng/directive/ngModel

Edit: Here's an example fiddle with binding your inputs to an array: https://jsfiddle.net/gxmw62rj/2/

Sign up to request clarification or add additional context in comments.

3 Comments

But If I want to sent array of fields to server? How as like: name="type[]"?
@Hamed - I made an update to show binding to an array.

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.