首页 > 解决方案 > AngularJS v1.8.0 ng-selected 选项不起作用

问题描述

我刚刚将 AngularJs 版本从 AngularJS v1.4.8 更新到 AngularJS v1.8.0,并且我有一个需要默认值的选择。由于某种原因,ng-selected 停止工作。你能告诉我如何在 1.8.0 上设置 ng-selected 吗?(代码使用 ng 模型)

        <input  name="questionamount" class="form-control uservalue" type="number" min="0" ng-model="userInput1" ng-disabled="content.NotRelevant" ng-blur="setMainFieldAsTouched(); updateFormVisibility()" ng-change="update('userInput1',userInput1)" val-bubble>
        <select name="questionperiod" class="form-control" ng-model="userInput2" ng-disabled="content.NotRelevant" ng-blur="setMainFieldAsTouched()" ng-change="update('userInput2',userInput2)" val-bubble>
            <option value="">-- Select a period --</option>
            <option value="48">Year</option>
            <option value="24">6 Months</option>
            <option value="12">Quarter</option>
            <option value="4" ng-selected="true">Month</option>
            <option value="5">Four Weekly</option>
            <option value="2">2 Weeks</option>
            <option value="1">Week</option>
        </select>       
        <input name="questionvalue" class="form-control" type="number" min="0" readonly ng-required="content.Mandatory && !content.NotRelevant" max="{{content.TriggerLimit}}" ng-change="update('content.Value',content.Value)" ng-blur="updateFormVisibility()" ng-model="content.Value" val-bubble>  
    </div> ```

Thanks in advance,

Jordi

标签: angularjs

解决方案


文档

注意:ngSelected 不与 select 和 ngModel 指令交互,它只在元素上设置 selected 属性。如果您在选择上使用 ngModel,则不应在选项上使用 ngSelected,因为 ngModel 将设置选择值和选定选项。

这意味着,将 userInput2 的值设置为您的默认值并且不要使用该ng-selected属性。另请参阅


推荐阅读