Reputation: 1205
i am working on a small app in angularJS and i have 2 json lists, 1 is called jsonPartners
and the other one is called jsonServices
.
I have a table with a select box inside my app that shows the partners names inside it and it is default selected to the partner name which id is inside each jsonService item like this
<tr ng-repeat="service in jsonServices">
<td>{{$index+1}}</td>
<td><select ng-model="service.partner_id" ng-options="partner.id as partner.name for partner in jsonPartners"></select></td>
</tr>
Now this works great, and the default name is selected correct but somewhere else in the app i have to add this name from jsonPartners based on the partner_id which matches with the partner_id from jsonServices.
This is how the jsonService and jsonPartners looks like
jsonServices = [{'partner_id':'5'}, {''partner_id':'7'}];
jsonPartners = [{'partner_id':'5','partner_name':'Dany'}, {''partner_id':'7', 'partner_name':'Andreea'}];
Is there a way to do that ? Thank you, Daniel!
Upvotes: 0
Views: 867
Reputation: 42669
You can use Angular filters like
$filter('filter')(jsonPartners, {'partner_id':selectedPartnerId})[0]
The final result is an array. See documentation http://docs.angularjs.org/api/ng.filter:filter
Upvotes: 2