###angularjs异步设置Select选择框的当前栏目为默认值 html
<div class="form-group"> <label class="col-sm-3 control-label no-padding-right ng-pristine ng-untouched ng-valid ng-binding" for="groupvalue" ng-change="gchange()" ng-model="selectGroup">更改组</label> <div class="col-sm-9"> <select style="float:left;width:83%" class=" ng-pristine ng-untouched ng-valid" ng-model="nggroup" ng-options="a.id as a.name for a in groups"> <!--<option value=""></option>--> </select> </div> </div>
angular:
$http.get('/api/v1.0/webs') .success(function (response) { $rootScope.groups = response.allgroup; $scope.groups = $rootScope.groups; }).error(function () { alert('获取数据失败'); });
//这里是你要给出当前栏目id,可以在html模板中给出groupid=12,然后在angularjs中取到: $scope.nggroup=groupid;
这里是关键:$scope.nggroup 对应ng-model="nggroup"
原文链接:https://www.f2er.com/angularjs/149443.html