2017-08-20 80 views
0

我已經搜索並嘗試了許多不同版本的代碼,但未找到任何答案。從選定的單選按鈕獲取angularjs值

我的代碼是:

<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> 

代碼:selected: {{aulPolicy.checked}} or {{policies.aul.name}}不顯示任何檢查,它只表示aul.name

任何想法?

下面我將我的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 
    }] 
} 

}

回答

2

我覺得下面的工作代碼將是對你有幫助。

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>

+0

謝謝你的迴應,我看你的代碼是如何工作的,並十分感謝使用最雷的給我看。但是,我仍然沒有得到它在我的應用程序中工作。 –

+0

我已經添加了我的json樣本,你有什麼想法嗎? –

+0

我已將所有代碼用於測試,並且不適合我。我發現它在stackoverflow片段中運行良好。有任何想法嗎? –