【问题标题】:Getting ng-repeat to work with populating radio button options让 ng-repeat 与填充单选按钮选项一起工作
【发布时间】:2016-03-15 01:07:06
【问题描述】:

我尝试使用 ng-repeat 填充单选按钮选项有什么问题?将 ng-repeat 与选择和复选框一起使用时,我没有同样的问题。非常感谢任何帮助。

"use strict";
angular.module("modalApp", [])
  .controller('modalCtrl', function($scope, $filter) {
    $scope.membershipTypeData = {
      availableOptions: [{
        id: '0',
        name: 'As a family (man and wife, or single person) we get the majority of our average GROSS income from sale of agricultural products produced by us or tenant. (Income from oil, gravel and other natural resources from land held for agricultural purposes counts as FARM income.)'
      }, {
        id: '1',
        name: 'I am retired from agriculture, living on income or Social Security accrued from agriculture and NOT employed full time in another occupation.'
      }, {
        id: '2',
        name: 'This membership is held by a partnership or corporation receiving the majority of income from sale of agricultural products.'
      }, {
        id: '3',
        name: 'I own or operate farmland, but my average gross agricultural income is less than half my total income. (Part-time farmers, landlords, etc.)'
      }, {
        id: '4',
        name: 'My occupation is in agri-business. I provide goods and/or services to agriculture or work for an agricultural organization or agency.'
      }, {
        id: '5',
        name: 'My occupation is NOT directly related to agriculture or agri-business.'
      }, {
        id: '6',
        name: 'This membership is held by a church, FFA chapter, an association or by a corporation NOT producing agricultural products.'
      }]
    };
  });
<html lang="en">

<body ng-app="modalApp">
  <div ng-controller="modalCtrl">
    <div>
      <form name="joinFormStep2" role="form">
        <label for="membershipType">Membership Type</label>
        <br />
        <div ng-repeat="membershipType in membershipTypeData">
          <label>
            <input type="radio" value="{{membershipType.id}}" ng-model="newMember.membershipType" ng-required="!newMember.membershipType">{{membershipType.name}}</label>
        </div>
        <br />
      </form>
    </div>
  </div>


  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.10/angular-ui-router.min.js"></script>

</body>

</html>

【问题讨论】:

  • 您在控制台中看到错误了吗?

标签: angularjs radio-button ng-repeat


【解决方案1】:

你需要使用

<div ng-repeat="membershipType in membershipTypeData.availableOptions">

你错过了 availableOptions

【讨论】:

  • 谢谢娜迦!粗心
猜你喜欢
  • 2016-03-25
  • 2022-11-11
  • 2015-06-27
  • 2023-03-25
  • 1970-01-01
  • 2015-09-22
  • 1970-01-01
  • 1970-01-01
  • 2013-05-01
相关资源
最近更新 更多