0

我以前遇到过这个问题,ng-src但我不知道如何用<select>. 非常简单的交易,但在选择下拉菜单显示后,该值无法更改。我试过了$apply()$compile()但没有任何运气。

我认为问题在于 Angular 不知道编译该元素。有任何想法吗?这是代码...

<blockquote class="header10">
  <label class="radio">
    <input type="radio" ng-model="panel.style" value="Rods and Rings">Rod and Rings
  </label>
  <select ng-hide="!(panel.style == 'Rods and Rings')" ng-model="panel.style.rodsAndRings">
    <option value="">--Choose Header--</option>
    <option>Butterfly Pleats (2 inch)</option>
    <option>Cuff Tops</option>
    <option>Fan Pleats</option>
    <option>Flat</option>
    <option>Goblet Pleats</option>
    <option>Inverted Box Pleats</option>
    <option>Pencil Pleats</option>
    <option>Pinch Pleats (4 inch)</option>
    <option>Tab Tops</option>
    <option>Tie Tops</option>
    <option>Other</option>
  </select>
  <div ng-hide="!(panel.style.rodsAndRings == 'Other')">
    <p>Other <input type="text"></p>
  </div>
</blockquote>

行为是,在显示select元素后,我仍然可以看到这些值,并且选择其中任何一个总是恢复为默认值--Choose Header--,因为它从未被采用。

Plunker 上的测试用例:http ://plnkr.co/edit/dTYcCi6aT3H5Gm7TEvyc?p=preview

4

1 回答 1

3

The problem is that panel.style.rodsAndRings isn't a valid ng-model. You defined panel.style to be a string primitive, so attaching a property to it won't work. Try changing your model to be something different, like panel.selected

Also I would recommend using angulars ng-options instead of hard coding in your options

于 2013-08-20T23:27:37.590 回答