0

This is what I did.

$scope.data.months = [];    
angular.forEach(response, function (value, key) {
      $scope.data.months.push({'month':value});
  });

console.log(response) is look like this

Array[3]
 0
 :
 "April 2017"
 1
 :
 "May 2017"
 2
 :
 "June 2017"

and console.log of months array result is look like this.

Array[0]
0 : Object
  month : "April 2017"
__proto__
:
Object
1 : Object
  month : "May 2017"
__proto__
:
Object
2 : Object
  month : "June 2017"
__proto__
:
Object

I have two question

-> First one is why it is showing Array[0] insist of Array[3] as there are three objects in this array.

-> Second one is how to count number of month I think if first one is solved then second one will be solved from first one.

I am newbie in angular js, What I am doing wrong please guide me through right direction.

Ramkishan Suthar
  • 403
  • 1
  • 7
  • 26

1 Answers1

0

Regarding to your first question. If console show 0 array and opening it show items in it then it is an unresolved promise issue. In other words, when you call your first console.log, the promise is not yet resolved, but resolving it in the meantime will show you the returned array if you open it.

For the second question, I think this might help you.

Community
  • 1
  • 1
neptune
  • 1,211
  • 2
  • 19
  • 32