Mark S
Mark S

Reputation: 51

Ng-repeat with Angular dropdown menu and Ruby on Rails API

Sorry if this has been answered before but I couldn't find a relevant answer. I'm new to both Ruby on Rails APIs and Angular so any help would be appreciated.

My API has 2 models. 'Property' model has properties of 'image' and 'price'. 'Place' model has the single property of 'location', and this model is also referenced inside the Property model.

I'm struggling with the syntax to drill down into the data and populate a list of locations on the page to edit property information. In the code below, the image update is working (url as a string) but I can't see data in the dropdown.

<form ng-submit="propertiesEdit.update()">
<div>
  <label>Image</label>
  <input type="text" ng-model="propertiesEdit.property.image">
</div>

<div>
  <label>Location</label>
  <select ng-model="propertiesEdit.property.place">
    <option disabled selected value="">Please select</option>
    <option ng-repeat="property in propertiesEdit.property.place" ng-value="{{ place.id }}">{{ propertiesEdit.property.place.location }}</option>
  </select>
</div>
</form>

Upvotes: 2

Views: 200

Answers (1)

Sudip
Sudip

Reputation: 48

Change the below line of code

  <option ng-repeat="property in propertiesEdit.property.place" ng-value="{{ place.id }}">{{ propertiesEdit.property.place.location }}</option>

To

  <option ng-repeat="locationProperty in propertiesEdit.property.place" ng-value="{{ place.id }}">{{locationProperty.location }}</option>

Upvotes: 0

Related Questions