我试图使用ng select和ng-options填充html表单中的数据,但无法找到答案。我的代码如下所示:
function get_areanames() {
$qry = mysql_query('SELECT * from tbl_area');
$data = array();
while($rows = mysql_fetch_array($qry))
{
$data[] = array(
"areaid" => $rows['areaid'],
"areaname" => $rows['areaname']
);
}
print_r(json_encode($data));
return json_encode($data);
}
$scope.get_areanames = function($scope,$http){
$http.get("library/function.php?action=get_areanames").success(function(data)
{
$scope.areaname = data;
});
}
<select class="form-control select2me" data-placeholder="Choose Area Name" name="areaname" ng-model="areaname" required> <option></option></select>
最佳答案
您需要使用ng-options
,考虑:
<select ng-options="item.areaid as item.areaname for item in areaname track by item.areaid"
ng-model="selectedArea"
class="form-control select2me"
name="areaname"
required>
<option value="">Choose Area Name</option>
</select>