如何NG-选定的工作?工作、NG

2023-09-13 04:30:31 作者:我身后空无一人

下面是一个片段。如我所料Q2被选中。

Here is a snippet. Q2 is selected as I expect.

<select name="quarter" ng-model="Quarter" >
    <option value="1" >Q1</option>
    <option value="2" ng-selected="Quarter=='Q1'">Q2</option>
    <option value="3">Q3</option>
    <option value="4">4</option>
</select>

修改Q1'Q2 '没有使选作我的期望。现在把 NG-选择=季=='Q1'不会使Q1选择,直到我删除 NG-选择=季==' Q2

Changing 'Q1' to 'Q2' makes nothing as selected as I expect. Now putting ng-selected="Quarter=='Q1'" DOES NOT make Q1 selected until i delete ng-selected="Quarter=='Q2"

跆拳道。这是怎么想的工作?

wtf. How is this suppose to work?

推荐答案

如果你把NG-选择的选项元素,你的选择会时NG-选择的值是真实的选择。在你的情况,该选项Q2被选中当季度等于Q1。

If you put the ng-selected on the option element, your option will be selected when the ng-selected value is true. In your case, the option Q2 is selected when Quarter is equal to Q1.

如果您想选择在城区传递的值,你必须把NG-选择的选择元素:

If you want to select the value passed in Quarter, you must put the ng-selected on the select element :

<select name="quarter" ng-model="Quarter" ng-selected="Quarter"
        ng-options="Quarter for Quarter in Quarters" >
    {{Quarter}}
</select>

看看在选择指令文档。