0

If I have a database schema set up like this

{ "name":  "Microsoft",
     "field": [
         "technology",
         "ai",
         "etc"
     ]
}

how can I get the data from angular? Calling:

{{company.field[]}}

doesn't work. I can only call an array index like

{{company.field[1]}}

4 Answers 4

2

Since the field property is an array, are you looking to iterate through to get those values?

You can use the ng-repeat directive

<div ng-repeat="item in company.field">
{{item}}
</div>
Sign up to request clarification or add additional context in comments.

Comments

1

The property field is not nested under the name property.

To access the array values you'll need to do company.field[n] where n is the index of the item or just dump the entire array like company.field.

See my JSFiddle.

2 Comments

My mistake. Messed up writing on my phone. In your example it prints out company.field[1]. How can I get everything inside company.field[].
@TerraNuva try {{company.field}} without []. I have updated my JSFiddle.
1
 //try this
 <div ng-repeat="val in company">
    {{val.name}}
    <div ng-repeat="obj in val.field">
       {{obj.technology}}
       {{obj.ai}}
       {{obj.etc}}
    </div>
 </div>

Comments

0
<script>

  var company =  { "name":  "Microsoft",
     "field": [
         "technology",
         "ai",
         "etc"
     ]
}
for(i=0;i<company.field.length;i++){
console.log(company.field[i])

}

</script>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.