Mahabub baig
Mahabub baig

Reputation: 177

Displaying details based on selected radio button

$scope.units.push({
  id: response[j]["productId"],
  itemPrice: response[j].productPrice,
  discountPrice: response[j].discountPrice,
  productUnit: response[j].productUnit
});

I have units array. It contains id, itemprice..fields with data. I am displaying radio buttons based on productunits. (I mean number of productunit is equal to number of radio buttons). If i select radio button then i want to display specific itemprice, discountprice. how to achieve it?

Upvotes: 0

Views: 53

Answers (1)

lucasnadalutti
lucasnadalutti

Reputation: 5948

Well, you are assigning the selected item to a scope variable called selectedPerson through ng-model. Thus, you can simply print the data outside the ng-repeat scope. Something like:

<p ng-repeat="item in units ">
    <label>
        <input type="radio" name="item" ng-model="selectedPerson" ng-value="item"/>
        {{item.productUnit}}
    </label>
</p>
<p>{{selectedPerson.itemPrice}} {{selectedPerson.discountPrice}}</p>

IMPORTANT: don't forget to initialize $scope.selectedPerson = {} in your controller so that selectedPerson belongs to your controller's scope instead of ng-repeat's scope.

Upvotes: 1

Related Questions