Does not pull a certain Array value

Asked

Viewed 93 times

0

I have a little problem in Angularjs

I need to pull the array values

angular.module('app', [])
.controller('Ctrl', ['$scope', function($scope) {

  $scope.data = [{
    a: 1,
    b: 2,
    c: [{
      d: "z",
      e: "4"
    },{
      d: "z",
      e: "4"
    }]
  }];  

}]);

Html

<div ng-repeat="i in data">
           <p>Não puxa: {{i.c.d}}</p>
           <p>Puxando o Valor: {{i.c.0.d}}</p>
 </div>

And unfortunately I can’t pull. Follow Link: http://plnkr.co/edit/Jdym3w7eT0KSMZAD72V4?p=preview

2 answers

0


Take the element square bracket c, after all you want to access it as object and not as array.

$scope.data = [{
  a: 1,
  b: 2,
  c: {
    d: "z",
    e: "4"
  },
  {
    d: "z",
    e: "4"
  }]
}];  
  • Good afternoon, all right? I want a loop in {{c.d}} E that way of the Error.. Follow my link http://plnkr.co/edit/Jdym3w7eT0KSMZAD72V4?p=preview Thank you.

  • You have a rather inconsistent structure. It starts with a array of 1 single element, this element that is inside has some attributes, being new hours arrays, hours possessing a value or still being a new element. Are you aware of this? Here is a suggestion of how to improve it a bit, or at least to be able to iterate to the level c: http://plnkr.co/edit/OcYQ3HJiMlSYNCm1a7nK

  • Another suggestion, use key/value to iterate an object, as long as it is actually an object, example for its data source: http://plnkr.co/edit/W2zyCulaZtrbODPlnK42

0

I managed to solve it that way:

<div ng-repeat="i in data">
   <p>Não puxa: {{i.a}}</p>     
   <p ng-repeat="day in i.c">Puxando o Valor: {{day.d}}</p>       
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.