angularjs中下拉框select 第一個為空白


<label for="userId">發起培訓人</label> <select
                class="form-control  input-sm" ng-model="trainDetail.userId" name="userId" id="userId">
                <option value="{{userId}}" selected="selected">{{realName}}</option>
                <option ng-repeat="user in userList"
                    ng-selected="user.id == trainDetail.userId" value="{{user.id}}">{{user.realname}}</option>
            </select>

上述代碼在頁面中 如下圖所示   第一行數據顯示空白

 

 

chrome解析錯誤代碼


<option value="? undefined:undefined ?"></option>

解決方式  :ng-init = "trainDetail.userId = userId"  初始化  select

<label for="userId">發起培訓人</label> <select
                class="form-control  input-sm" ng-model="trainDetail.userId" name="userId" id="userId" ng-init = "trainDetail.userId = userId">
                <option value="{{userId}}" selected="selected">{{realName}}</option>
                <option ng-repeat="user in userList"
                    ng-selected="user.id == trainDetail.userId" value="{{user.id}}">{{user.realname}}</option>
            </select>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM