2

im working with the angularjs framework. Here is my Code first:

var app = angular.module('app',['ngRoute','ngAnimate']);

app.controller('maincontroller',function($scope,$http) {
    $scope.planes = [];

    $scope.createPlanes = function() {
        $http.post('api/create_plane.php',{
        }).success(function(data,status,headers,config) {
            console.log(data);
            for(var result in data)
                {
                    $scope.planes = [
                        {"planeLMID": data[result]['planeLMID']}
                    ];
                }
            console.log($scope.planes);
        });
    };
    $scope.createPlanes();
});

And this is the return of the console.log(data);

Object {1: Object, 2: Object, 3: Object, 4: Object, 5: Object, 6: Object, 7: Object, 8: Object, 9: Object, 14: Object, 15: Object, 16: Object, 17: Object, 18: Object, 20: Object, 21: Object, 23: Object, 24: Object, 25: Object, 26: Object, 27: Object, 29: Object, 31: Object, 32: Object, 33: Object, 34: Object, 35: Object, 36: Object, 37: Object, 38: Object}

And a sample of how a object in it look like

planeAFID:    "89-3412"
planeCPISPI:    ""
planeLMID:     "8215"

so i want to do a $scope.planes array with a for loop. But after the first object it doenst fill anymore. How can i push the other objects into the array?

Thanks

2
  • 1
    You could do $scope.planes.push( {"planeLMID": data[result]['planeLMID']}) Commented Sep 30, 2016 at 12:38
  • Oh god, sorry for that small fail from me. Thanks anyway Commented Sep 30, 2016 at 12:40

4 Answers 4

1

You need to implement the push method, $scope.planes.push('insert what you want to push here')

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

Comments

0

using push function of the array you can achive this.

$scope.planes=[];
for(var result in data)
{
  $scope.planes.push({"planeLMID": data[result]['planeLMID']});

}
console.log($scope.planes);

Comments

0

You should use the array's .push() method

var app = angular.module('app',['ngRoute','ngAnimate']);

app.controller('maincontroller',function($scope,$http) {
    $scope.planes = [];

    $scope.createPlanes = function() {
        $http.post('api/create_plane.php',{
        }).success(function(data,status,headers,config) {
            console.log(data);
            $scope.planes = [];
            for(var result in data)
            {
                $scope.planes.push({"planeLMID": data[result]['planeLMID']})
            }
            console.log($scope.planes);
        });
    };
    $scope.createPlanes();
});

Comments

0

you can use something like this.

$scope.planes = [];

$scope.createPlanes = function() {
    $http.post('api/create_plane.php',{
    }).success(function(data,status,headers,config) {
        console.log(data);
        for(var result in data)
            {
                $scope.planes.push({
                    "planeLMID": data[result]['planeLMID']
                });
            }
        console.log($scope.planes);
    });
};
$scope.createPlanes();

Comments

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.