0

I believe I'm following correctly the AngularJS official documentation for radio buttons.

So, I created this code:

indexSelected={{indexSelected}}
<form name="form">
    <div class="form-group">
        <label ng-repeat="s in prices track by $index" style="width: 100%">
            <input type="radio" name ="option" ng-model="indexSelected" value="{{s.months}}"> {{s.price}} + vat
        </label>
    </div>
</form>

Also, I made other attempting using ng-value, like this...

indexSelected={{indexSelected}}
<form name="form">
    <div class="form-group">
        <label ng-repeat="s in prices track by $index" style="width: 100%">
            <input type="radio" name ="option" ng-model="indexSelected" ng-value="s.months"> {{s.price}} + vat
        </label>
    </div>
</form>

and this is my controller

angular
.module('app')
.controller('ModalInstanceUpgradeSolutionCtrl', function ($scope,$rootScope, $uibModalInstance, appId) {
    $scope.prices = [{
        months: 1, price : 20
        }, { months 2: price: 40}]
     });

The question is: What could be wrong ? because when I click on the radio buitton, this is not updating the model indexSelected. Any clue ?

1
  • 1
    You are breaking the golden rule of not using an object in ng-model and thus will run into child scope problems due to ng-repeat Commented Feb 25, 2017 at 13:36

1 Answer 1

1

Ok, found the error. @charlietfl gave me some hint. Enough to google it.

If I replace ng-model="indexSelected" for ng-model="$parent.indexSelected", this will access the parent scope. ng-repeat creates a child scope.

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

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.