2

This is my code:

    <label ng-repeat="option in product.DeliveryOptions" class="radio-inline product__filtr__form__label__input">
  <input type="radio" ng-model="product.SelectedDeliveryOption" ng-change="changeDeliveryType(product)" name="inlineRadioOptions{{product.ID}}"
class="product__filtr__form__radio" value="{{option.Method}}">{{option.Description}}
</label>

This is nested ng-repeat block. Parent block is product in products. As you can see each product has SelectedDeliveryOption. For example I have two radio buttons. Values(option.Method) - "bronze" for the first and "silver" for the second. This value (ng-model="product.SelectedDeliveryOption") is "silver". But radio button isn't selected by default. I've tryed: ng-checked = "option.Method == product.SelectedDeliveryOption", but doesn't work for me.

 $scope.initProductsTable = function (products) {
            $scope.products = products;    }

Could anyone help me?

8
  • Where is the javascript Code ? Commented Aug 14, 2016 at 20:56
  • please provide the js code as snippet Commented Aug 14, 2016 at 21:00
  • Just initialization of products $scope.initProducts = function(products){$scope.products = products}; and <div ng-init="initProducts(products)"></div> Commented Aug 14, 2016 at 21:00
  • how $scope.products = products looks like? Commented Aug 14, 2016 at 21:01
  • Edited my question. As I know, usual ng-init Commented Aug 14, 2016 at 21:03

1 Answer 1

1

Make sure if the value object option.Method in:

<input type="radio" ng-model="product.SelectedDeliveryOption" ng-change="changeDeliveryType(product)" name="inlineRadioOptions{{product.ID}}"
class="product__filtr__form__radio" value="{{option.Method}}">

has the format:

option.Method = {"id": "12345",
            "value": "teste"}

and use ng-value directive;

like the example bellow:

When using radio button you have to make equal the model value and the value from the radio button:

check the snippet bellow:

(function(angular) {
  'use strict';
  angular.module('includeExample', ['ngAnimate'])
    .controller('ExampleController', ['$scope', '$q',
      function($scope, $q) {
       $scope.color = {
        name: 'blue'
      };
      $scope.specialValue = {
        "id": "12345",
        "value": "green"
      };        


      }
    ]);
})(window.angular);
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.1/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-beta.1/angular-animate.js"></script>

<body ng-app="includeExample">
  <div ng-controller="ExampleController">
    <form novalidate class="simple-form">
    <label>
    <input type="radio" ng-model="color.name" value="red">
    Red
  </label><br/>
  <label>
    <input type="radio" ng-model="color.name" ng-value="specialValue">
    Green
  </label><br/>
  <label>
    <input type="radio" ng-model="color.name" value="blue">
    Blue
  </label><br/>
  <tt>color = {{color.name | json}}</tt><br/>
  </form> 

  </div>
</body>

Sign up to request clarification or add additional context in comments.

2 Comments

Alvaro, I've found a mistake. Thank you very much for help. The name of radio buttons was the same. Really, don't know how I missed it. Thanks a lot for your time.
Np, I'm happy if I helped :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.