如何从angularjs中的选择框中获取选定的值

Sha*_*ram 5 javascript angularjs

大家好

我试图从按钮单击的选择框中获取选项值,但它在控制台中显示未定义.Options值来自服务器

这是我的HTML代码

<div class="form-group">
        <label class="control-form" for="cityid">Selct City</label>
        <select type="text" class="form-control" placeholder="City" id="acity" >
            <option value="">--Select City--</option>
            <option ng-repeat="city in cityinfo" ng-value="{{city.id}}"  ng-selected="{{city.id ==cityid}}">{{city.cityname}}</option>
</select>

<button class="btn btn-info prevnext pull-right" ng-click="nextpage()">Next <i class="fa fa-arrow-right"></i></button>
Run Code Online (Sandbox Code Playgroud)

Controller.js文件代码

  $scope.nextpage = function(pageno) {
   console.log($scope.cityinfo);
   }
Run Code Online (Sandbox Code Playgroud)

选择框图像

提前致谢

Roy*_*Roy 10

ng-options而不是ng-repeat.

像这样:

更新

<select type="text" class="form-control" placeholder="City" id="acity" ng-options="city.id as city.cityname for city in cityinfo track by city.id" ng-model="selectedCity">
    <option value="">--Select City--</option>
</select>
<button class="btn btn-info prevnext pull-right" ng-click="nextpage(selectedCity)">Next <i class="fa fa-arrow-right"></i></button>
Run Code Online (Sandbox Code Playgroud)

JS:

$scope.nextpage = function(selectedCity){
    console.log(selectedCity);
}
Run Code Online (Sandbox Code Playgroud)