I have a MEANJS app with a CRUD module of countries. When I click on a country from the default list view, it brings me to the view-country.client.view. I have added a field to my model for currencycode. When I click the country it will bring me to a page where I want it to bring up the exchange rate from a json by matching the currencycode field of the Country model with my data from the json import.
//view-country.client.view
<section data-ng-controller="CountriesController" data-ng-init="findRate()">
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="panel panel-dark">
<div class="panel-heading">Currency</div>
<div class="panel-body">
{{country.currencycode}}
<p>The exchange rate is {{exchangeRates.rates['AFN']}}
</div>
</div>
</div>
</section>
//findRate() for data-ng-init in CountriesController
$scope.findRate = function() {
$scope.country = Countries.get({
countryId: $stateParams.countryId
});
$http.get('http://localhost:3000/rates.json').
success(function(data) {
$scope.exchangeRates = data
});
};
Everything is working with the JSON import and if I include the countrycode (in this example 'AFN' for Afghanistan), it will return the correct rate. The {{country.currencycode}} brings back AFN from my MongoDB but if i try and embed the {{country.currencycode}} where 'AFN' is, it will not work. I have tried looking at filters but I cannot get those to work. Basically, anytime I click a country, I want it to show only the rate for that country by using the model property as a string for getting the correct object from my array. I have been in forums all day and cannot figure this out. Thank you in advance.
If I understood correct, you don't want 'AFG' to be hardcoded here?
{{exchangeRates.rates['AFN']}}
If that's the case have you tried this?
{{exchangeRates.rates[country.currencycode]}}