我有一個場景,我需要在ng-repeat內部動態創建下拉列表,並且下拉列表的數據源也是動態的,這意味着基於我需要綁定我的下拉列表的查詢。ng-options的angularJS控制器方法
因此,我致力於通過傳遞基於查詢的查詢來調用控制器方法,其中我有一個http get,我的服務將返回帶有鍵值對的通用數據。當我調用控制器方法,我結束了王氏infinte循環
錯誤:$ rootScope:infdig 無限$消化循環
我的HTML
<table style="width: 100%">
<tr>
<td colspan="2"><strong>Enter Parameters</strong></td>
</tr>
<tr ng-repeat="x in reportDataParameter.UserParameterList">
<td>{{x.UserParamDefinition.DisplayLabel}}</td>
<td>
<select ng-model="x.Model" ng-options="item.ValueField as item.TextField for item in executeQuery(x.UserParamDefinition.Query)" class="form-control">
<option value="">Please Select</option>
</select>
</td>
</tr>
</table>
控制器
$scope.reportDataParameter = {};
$scope.reportDataParameter = {
"UserParameterList": [
{
"Key": "StateID",
"Value": "?ddl,State,State",
"UserParamDefinition": {
"DataType": "ddl",
"DisplayLabel": "State",
"Model": null,
"Query": "SELECT Id AS ValueField, BankName AS TextField FROM BankDetail"
}
},
{
"Key": "FacilityParentID",
"Value": "?ddl,FacilityParent,FacilityParent",
"UserParamDefinition": {
"DataType": "ddl",
"DisplayLabel": "FacilityParent",
"Model": null,
"Query": "SELECT Id AS ValueField, Name AS TextField FROM Organization"
}
}
],
"ReportTitle": "Facility List By Parent",
"Description": null,
"ReportPage": null
};
$scope.executeQuery = function (query) {
var baseUrl = 'https://localhost:62';
return $http.get(baseUrl + '/api/reports/executequery/' + query).then(function (result) {
return result.data;
});
}
我建議你儘可能簡化你的代碼問題:讀者和你的一切都會變得更加清晰...... :-)你也應該閱讀你的介紹性文字(第二句expecially )... – MarcoS