Learner Learner - 4 months ago 8
AngularJS Question

how to display name of a particular code from a javascript object in angular js and html5

I have a angular controller that has the following array which has 3 values.

controller.medicalInstitues;


I want to take the 4th object in the array with code "AUS". Then further, I want to display the name of only 2 medical institutes with the code as "SYD" and "MEL" within that choosen bject from the parent array.

something like below:

var country = select controller.medicalInstitues.countryCode = "AUS"
var institues = select controller.medicalInstitues.name from country.code="SYD" and "MEL";

now I need to bind these in the UI (Angular).

<span class="code"> {{ controller.institutes.name }}</span>

Answer

Suppose you have got your list of values in medicalInstitues, then in the angularjs controller you can do

$scope.institues = medicalInstitues.filter(function(value){
    return value.countryCode == "AUS" && (value.code == "SYD" || value.code == "MEL");
});

In HTML you can use ng-repeat:

<div controller="controller">
    ....
    <span ng-repeat="institue in institues">{{institue.name}}</span>
    ....
</div>