我试图使用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>
答案 0 :(得分:1)
您需要使用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>
答案 1 :(得分:1)
您需要将ng-options属性添加到您的选择中:
<select ng-options="areaitem.areaname for areaitem in areaname" ....
这将填充范围中的areaname数组中的选项。