I
I
Ilya2014-08-23 10:13:39
Angular
Ilya, 2014-08-23 10:13:39

How to get data from radio buttons in AngularJs?

Hello. I'm trying to get data from radio buttons. In this case, the radio buttons are generated from an array using ng-repeat. Tell me how to get the name and price of the selected element.
Help!
jsfiddle.net/hanze/j9x23apu
**html**

<h1>Select </h1>

    <div ng-app="" ng-controller="OrderCtrl">
          <div ng-repeat="item in items">
    <div class="radio">
    <label>
         <input type="radio" name="item" ng-model="item" ng-checked="{{item.checked}}"> 
         {{item.name}} +{{item.price}} $.</label>
    </div>
    </div>

    Your choice: {{}} **what i must write here?**
    <br>
    Price: {{}} **and here?**
    </div>

**js**

OrderCtrl = function ($scope) {
    $scope.items = [{
    name: 'None',
    value: "no",
    price: 0,
    checked: true
    }, {
    name: 'Black',
    value: "black",
    price: 99,
    checked: false
    }, {
    name: 'White',
    value: "white",
    price: 99,
    checked: false
    }, {
    name: 'Barhat',
    value: "barhat",
    price: 49,
    checked: false
    }, {
    name: 'Barhat',
    value: "cream",
    price: 49,
    checked: false
    }]

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2014-08-23
@AMar4enko

jsfiddle.net/217cxjmy

K
Krio, 2014-08-23
@Krio

A couple more options :
jsfiddle.net/j9x23apu/20
+ if we need to track the change, we can add ng-change="changed()"
2. Based on ng-click, specify the action on click and immediately pass the item
ng-click="selectItem(item)"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question