【发布时间】:2017-06-03 06:55:43
【问题描述】:
这里我想使用 Angular 在选择框中加载数据库用户。
<div ng-app="myapp" ng-controller="myctrl" class="centered">
<label>Select User</label>
<select ng-model="selectedItem" ng-options="item.name for item in list">
<option value="">-- choose --</option>
</select>
<h2>Selected:</h2>
{{selectedItem.name}}
</div>
<script type="text/javascript">
var app=angular.module('myapp',[]);
app.controller('myctrl', function($scope, $http) {
$http({
method : "GET",
url : "http://localhost/demo/angular/getdata.php"
}).then(
function (response) {
$scope.list = response.data.records;
});
});
</script>
【问题讨论】:
-
我使用了 Angular 版本 2
-
输出 : {"records":[{Name : "Reena"},{Name : "Diya"},{Name : "New"},{Name : "New1"},{Name : "Diya"},{Name : "Sonali" },{Name : "Sonali"},{Name : "Sonali"},]}
-
PHP 中没有返回参数,使用“return $outp”然后再试一次,你使用的角度 1 不是角度 2。
-
您的命令似乎您使用的是 angular 1.x 而不是 2.x
-
是角度 1.8
标签: javascript php mysql angularjs