简体   繁体   中英

get angularjs value from selected radio button

I have searched and tried many different versions of code but not found any answer.

My code is:

<div class="well">
    <h3>{{policies.aul.name}}</h3>
    <ul style="list-style: none;">
        <li ng-repeat="p in policies.aul.policies | orderBy:'!pName' ">
            <input type="radio" ng-model="aulPolicy.checked" name="{{policies.aul.name}}" ng-value="{{p.pName}}" required /> {{p.pName}}
        </li>
    </ul>
    selected: {{aulPolicy.checked}} or {{policies.aul.name}}
    <input type="submit" class="btn btn-primary" onclick="javascript:generateTableA('{{aulPolicy}}')" value="Build">
    <input ng-hide="!aData" type="submit" class="btn btn-primary" value="Add Table" disabled="true">
    </span>
</div>

The code: selected: {{aulPolicy.checked}} or {{policies.aul.name}} does not show anything checked , it does show aul.name .

Any ideas?

Below I have added my json:

{"aul":{"name":"American United Life",
"policies":[{
    "pName":"standard",
    "header":[{"name":"Policy Year","total":false},{"name": "Age","total":false},
    {"name":"Contract Premium","total":true},{"name":"Cash Value","total":false},
    {"name":"PUA Cash Value","total":false},{"name":"Death Benefit","total":false},
    {"name":"Total Annual Outlay","total":false},{"name":"PUA Cash Value","total":false},
    {"name":"Total Net Cash Value","total":false},{"name":"PUA Death Benefit","total":false},
    {"name":"OTA Death Benefit","total":false},{"name":"Total Net Death Benefit","total":false},
    {"name":"Total","total":false}],
    "cols":12
    },
    {"pName":"offset",
        "header":[],
        "cols":13
    },
    {"pName":"level trem",
        "header":[],
        "cols":13
    },
    {"pName":"blended term",
        "header":[],
        "cols":13
    },
    {"pName":"blended and level",
        "header":[],
        "cols":12
    },
    {"pName":"blended and level and offset",
        "header":[],
        "cols":15
    }]
}

}

I think below working code will be helpful for you.

 var app = angular.module('plunker', []); app.controller('MainCtrl', function ($scope) { $scope.policies = { aul: { name: 'Test', policies: [ { pName: '1' }, { pName: '2' }, { pName: '3' }, { pName: '4' }, { pName: '5' } ] } }; $scope.aulPolicy = {}; }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" ></script> <div ng-app="plunker" ng-controller="MainCtrl"> <div class="well"> <h3>{{policies.aul.name}}</h3> <ul style="list-style: none;"> <li ng-repeat="p in policies.aul.policies | orderBy:'!pName' "> <input type="radio" ng-model="aulPolicy.checked" name="{{policies.aul.name}}" ng-value="{{p.pName}}" required /> {{p.pName}} </li> </ul> selected: {{aulPolicy.checked}} or {{policies.aul.name}} <input type="submit" class="btn btn-primary" value="Build" /> <input ng-hide="!aData" type="submit" class="btn btn-primary" value="Add Table" disabled="true" /> </div> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM