在选项上选择angularJS不起作用

时间:2014-08-20 07:06:16

标签: javascript html angularjs selection

场景 - 以下是我的HTML选择框代码,在选择Every Day选项时,假设选择Everyday选择并选择日期选择选项从2开始。

问题 - 虽然div正确打开但每天选项不是pre selected而且日选择下拉也不是从2开始,就像我相信应该。

让我知道我在这里做错了什么。

HTML代码 -

<div>
    <select
        id="repeatval"
        ng-model="event.repeat"
        ng-options="repeat.value as repeat.name for repeat in repeats"
        ng-init="event.repeat = event.repeat || repeats[0].value"
        class="btn">
    </select>
</div>
<div ng-if="event.repeat === 2">
    <input type="radio" name="everyday" ng-model="event.everyday" value="forever" ng-checked="true" /> Everyday
    <input type="radio" name="everyday" ng-model="event.everyday" value="dayselval" />
    Select <select
            id="selday"
            ng-model="event.selday"
            ng-options="day.value as day.name for day in days"
            ng-init="event.day = event.day || days[0].value"
            class="btn">
           </select> Day
    <input type="radio" name="everyday" ng-model="event.everyday" value="pickdate" /> Pick a date
</div>

Plnkr - PLNKR DEMO

编辑 -

广告/ Vamsi评论 - 我通过应用 -

解决了选择问题

ng-init="event.selday = event.day || days[0].value"

event.day更改为event.selday

1 个答案:

答案 0 :(得分:2)

如果您想要选择输入广播,可以设置ng-value="forever"

要选择该选项,您必须设置ng-model值,在您的情况下,未选择该值,您可以使用ng-init执行此操作:

 Select <select
                id="selday"
                ng-init="event.selday = 2"
                ng-model="event.selday"
                ng-options="day.value as day.name for day in days"
                ng-init="event.day = event.day || days[0].value"
                class="btn">
               </select> Day