这里我想使用 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>
最佳答案
完全依赖后端。如果后端是 RESTFull 服务,那么从服务器获取数据并填写表单就很容易。
顺便说一下,从后端获取数据与编程语言无关。下面是Java+Angularjs的例子
https://spring.io/guides/gs/consuming-rest-angularjs/
这是一个展示如何在 PHP 中实现 RESTFull API 的示例:
https://www.leaseweb.com/labs/2015/10/creating-a-simple-rest-api-in-php/
关于javascript - 如何在angularjs中从数据库mysql加载动态记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44341247/