Plunkr:https://plnkr.co/edit/ubAPmJoMQaKBLvWSsmTv?p=preview
在我的应用程序中,当我第一次切换打开此下拉列表时:
关闭并重新打开下拉列表后:
我的加价:我设置了ng-init="vh.loadedViews[0].description"
,不知道为什么会发生变化:(
<section class="saved-views-modal" ng-show="vh.loadSavedModal">
<header><h1>Select a saved view</h1></header>
<div class="select-style">
<select name="select"
ng-init="vh.loadedViews[0].description"
ng-show="vh.viewsAvaliable"
ng-model="vh.description"
ng-change="vh.chooseView(vh.description)">
<option ng-repeat="view in vh.loadedViews"
ng-init="vh.description=vh.loadedViews[0].description"
value="{{ view.description }}">{{ view.description }}</option>
</select>
<select ng-hide="vh.viewsAvaliable" name="select">
<option selected="selected" value="No saved views">No saved views</option>
</select>
</div>
<button class="btn-green" ng-click="vh.loadView()">Load View</button>
<button class="btn-green" ng-click="vh.deleteView()">Delete View</button>
</section>
我刚注意到标记?undefined:undefined ?
答案 0 :(得分:4)
您必须在select而不是
中提供ng-init喜欢这个
<select name="select" ng-init="description=loadedViews[0].description" ng-model="description" ng-change="chooseView()">
<option ng-repeat="view in loadedViews" value="{{ view.description }}">{{ view.description }}</option>
</select>
的 DEMO
强>
但最好使用 ngOptions
喜欢这个
<select name="select" ng-init="description=loadedViews[0].description" ng-model="description" ng-options="view.description as view.description for view in loadedViews" ng-change="chooseView()">
</select>
的 DEMO
强>