0

I have spent a lot of time trying out the solutions I found on SO but nothing seems to work for me. I created the jsfiddle based on a solution I found on SO below ...but still doesn't work.

There are a few issues: 1) a default for selected radio doesn't work 2) when selecting a radio button it doesn't update the model but appears to wipe it out

Please have a look at my fiddle and let me know if I have done something totally stupid. https://jsfiddle.net/findjon/z99dp7nq/

index.html

<div class="radio" data-ng-repeat="option in pudoOptions">
   <input type="radio" data-ng-model="selected.deliveryType" data-ng-value="deliveryType" />{{ option.name }}
</div>
{{ selected.deliveryType }}

controller

$scope.pudoOptions = [{name:'standard'},{name:'nextDay'}];
$scope.selected = {
  deliveryType : $scope.pudoOptions[0]
};

2 Answers 2

2

Seems your code need some changes.

<div ng-app="testApp" ng-controller="testController">

    <div class="radio" ng-repeat="option in pudoOptions">
      <input type="radio" ng-model="selected.deliveryType" value="{{option.name}}" name="deliverType"/>
      {{ option.name }}
    </div>

    {{ selected.deliveryType }}
</div>

In controller.js:

var app = angular.module('testApp', []);

app.controller('testController', ['$scope', function($scope) {

  $scope.pudoOptions = [{name:'standard'},{name:'nextDay'}];

  $scope.selected = {
    deliveryType : $scope.pudoOptions[0].name
  };

}]);

Its working for me.

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

Comments

0

try this

<div ng-app="testApp" ng-controller="testController">

    <div class="radio" ng-repeat="option in pudoOptions">
      <input name ="rname" type="radio" ng-model="selected.deliveryType" ng-value="option" />
      {{ option.name }}
    </div>

    {{ selected.deliveryType }}
</div>

Comments

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.