根据Angular JS中的单选按钮选择填充下拉列表

时间:2017-10-06 13:02:38

标签: angularjs

我正在尝试根据单选按钮选择填充下拉选项。

以下是我的代码

HTML

<md-radio-group ng-model="cat_type">

<md-radio-button  ng-repeat="category in  categories" value="{{ category }}" class="md-primary">
{{ category.name }}</md-radio-button>

</md-radio-group>

 <select class="form-control" ng-model="cat_list" ng-options="type.id as type.name for type in cat_type.types"></select>

JS

$scope.categories= [
    {
        "id": 1,
        "name": "Allowance",
        "types": [
            {
                "id": 1,
                "category_id": 1,
                "name": "Overtime"
            },
            {
                "id": 2,
                "category_id": 1,
                "name": "Bonuses"
            }
        ]
    },
    {
        "id": 2,
        "name": "Deduction",
        "types": [
            {
                "id": 3,
                "category_id": 2,
                "name": "Loan"
            },
            {
                "id": 4,
                "category_id": 2,
                "name": "surcharges"
            }
        ]
    }
     ]

它列出单选按钮,但点击任何单选项后,选项

没有任何反应

1 个答案:

答案 0 :(得分:0)

尝试为单选按钮指定模型,然后在ng-options

中使用category.types