角度选择选项ng-repeat

时间:2016-06-02 09:50:49

标签: angularjs angularjs-ng-repeat

我无法选择使用ng-repeat on选项。

问题是我的代码在plunkr上工作得很好但不在我的项目中。 该列表中未预先选择该字段:

enter image description here 所以我们可以看到变量不是null(包含" subf。")

the plunkr:https://plnkr.co/edit/OMDKOeAFE8aCoX6fB6Vx?p=preview

html代码:

          <div class="form-group row">
                <label for="rrtestListeTmp"> Repeat select:{{testListeTmp.value}} </label>
                <select id="rrtestListeTmp" name="rrtestListeTmp" ng-model="testListeTmp.value">
                    <option ng-repeat="(key,value) in testListeTmp.liste" value="{{key}}">
                        {{value}}
                    </option>
                </select>
            </div>

JS:

        $scope.testListeTmp = {
            'value': "subf.",
            'liste': {
                "subsp.": "subspecies",
                "var.": "varietas",
                "subvar.": "subvarietas",
                "f.": "forma",
                "subf.": "subforma"
            }
        };

2 个答案:

答案 0 :(得分:0)

您是否尝试在ng-init中使用<select>初始化模型的值?

答案 1 :(得分:0)

这种语法最终起作用

<select class="form-control input-md" 
        ng-model="testListeTmp.value"
        ng-options="key as value for (key , value) in testListeTmp.liste">
</select>
相关问题