[英]Can not set the value in drop down using angular.js and php
I am facing little bit problem to set data as drop down selected value after fetching from database.I am explaining my code below. 从数据库中获取数据后,将数据设置为下拉选择值时遇到一点问题。我在下面解释我的代码。
plan.html: plan.html:
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Date :</span>
<datepicker date-format="MMMM d, y" date-min-limit="2010/01/01" date-max-limit="2020/01/01"button-prev='<i class="fa fa-arrow-circle-left"></i>' button-next='<i class="fa fa-arrow-circle-right"></i>'>
<input type="text" name="birthdate" class="form-control" ng-model="date" placeholder="Add date" />
</datepicker>
</div>
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Topic :</span>
<input type="text" name="topic" class="form-control" ng-model="topic" placeholder="Add Topic" />
</div>
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Section:</span>
<select id="coy" name="coy" class="form-control" ng-model="section" ng-options="sec.name for sec in listOfSection track by sec.value " >
<option value="">Select section</option>
</select>
</div>
The related controller file code is given below. 相关的控制器文件代码如下。
$scope.listOfSection=[];
$http({
method:'GET',
url:"php/userplan/getSectionData.php",
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
angular.forEach(response.data,function(obj2){
var data={'name':obj2.section_name,'value':obj2.section_id};
$scope.listOfSection.push(data);
});
},function errorCallback(response) {
});
$http({
method:'POST',
url:"php/userplan/editPlanData.php",
data:planid,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
$scope.date=response.data[0].date;
$scope.topic=response.data[0].topic;
$scope.section=response.data[0].section_id;
$scope.buttonName="Update";
$scope.showCancel = true;
},function errorCallback(response) {
});
Here the response.data[0].section_id
should set in the drop down as value and the respective name should display.Here i tried by adding $scope.section.value=response.data[0].section_id
but it gave me the error.Here my requirement is section_id should set as value of the drop down and the respective name should display.Please help me to resolve this issue. 在这里, response.data[0].section_id
应该在下拉列表中设置为值,并且应该显示相应的名称。在这里,我尝试通过添加$scope.section.value=response.data[0].section_id
尝试,但是它给了我错误。在这里,我的要求是将section_id设置为下拉菜单的值,并显示相应的名称。请帮助我解决此问题。
you can use like this
<select ng-model="ContentAdditionalInfoModel.AdditionalInfoId" class="form-control" ng-required="true"
ng-options="item.AdditionalInfoId as item.AdditionalInfoName for item in AdditionalInfoList">
<option value="" selected="selected">Select</option>
</select>
here AdditionalInfoList come from your database
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.