ng-repeat内部的ng-selected不起作用(AngularJS)

时间:2018-03-18 22:20:28

标签: angularjs select angularjs-ng-repeat comparison option

我试图将值与'#34;检查&#34;进行比较。我的<option>代码中包含<select>代码,但无法找到解决方案...

*这是一个管理页面,因此我已经拥有{{x.nivel}}值。我只需将其标记为&#34;选择&#34;根据每个&#34; inscritos&#34;来自ng-repeat

帮助:\

            <li ng-repeat="x in inscritos | orderBy:'nome'">
                <select>
                    <option ng-selected="(this.value)=={{x.nivel}}" value="Iniciante">Iniciante</option>
                    <option ng-selected="(this.value)=={{x.nivel}}" value="Intermediário">Intermediário</option>
                    <option ng-selected="(this.value)=={{x.nivel}}" value="Avançado">Avançado</option>
                </select>
        </li>

1 个答案:

答案 0 :(得分:2)

不要在js表达式中使用{{}}

 <li ng-repeat="x in inscritos | orderBy:'nome'">
    <select>
       <option ng-selected="x.nivel=='Iniciante'" value="Iniciante">Iniciante</option>
       <option ng-selected="x.nivel=='Intermediário'" value="Intermediário">Intermediário</option>
       <option ng-selected="x.nivel=='Avançado'" value="Avançado">Avançado</option>
     </select>
 </li>

双花括号符号{{ }}用于将值与html元素绑定。请参阅templates文档。