0

I am new to AngularJS

And i have trouble to set dynamic key value.

Here is my code,

VIEW

<td>
    <input type="number" class="form-control" ng-model="title[id]" />
</td>

Controller

$scope.update = function() {
    $http({
        url: 'update.php',
        method: "POST",
        data: $scope.title
    }).success(function (data) {});
}

PHP

[amount] => Array
    (
        [0] => 
        [1] => 
        [2] => 
        [3] => 
        [4] => 
        [5] => 
        [6] => 
        [7] => 
        [8] => 
        [9] => 10
        [10] => 
        [11] => 
        [12] => 12
    )

So, my question is if i use id as input array key then always array start with 0 index not specific index.

Thank you !

4
  • What is id here? Please make it more clear. Can you provide more code. Commented Dec 30, 2017 at 8:39
  • Please check console : fiddle Commented Dec 30, 2017 at 8:45
  • If I am right then you want to set your $scope.name with the given id (like 12 here) and the array should not be start with 0. Am I right? Commented Dec 30, 2017 at 8:54
  • check my answer on your other question, it should solve this one as well stackoverflow.com/questions/48032358 Commented Dec 30, 2017 at 9:21

0

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.