我有一个选择标签,其中包含由 AngularJS 填充的选项。如果它等于范围内的另一个属性,我正在尝试选择一个选项。我试图比较的选项值和范围属性都来自异步 http 调用。所以总是有延迟,然后它就不能正常工作。确保两个范围属性都已解析并准备好进行比较的最佳实践是什么。
ng-selected="MusteriId == option.Value"
是比较部分。
<select id="MusteriId" name="MusteriId" ng-model="MusteriId">
<option ng-selected="MusteriId == option.Value"
ng-repeat="option in MusteriList" value="{{option.Value}}">
{{option.Text}}
</option>
</select>
这是我的控制器,其中执行了两个 http 调用。
(function() {
var biletController = function ($scope, $http, commonFunctions) {
$scope.Id = null;
$scope.BiletNo = null;
$scope.BiletTarihi = null;
$scope.CurrencyId = null;
$scope.MusteriId = null;
$scope.PAID_EUR = null;
$scope.PAID_TL = null;
$scope.PAID_USD = null;
$scope.ServisIstiyorMu = null;
$scope.TOTAL = null;
$scope.TourId = null;
$scope.MusteriList = null;
$scope.openEditFormJS = function(e) {
$http.get('/Bilet/Get/' + e)
.then(function (response) {
console.log(response.data);
$scope.Id = response.data.Id;
$scope.BiletNo = response.data.BiletNo;
if (response.data.BiletTarihi) {
$scope.BiletTarihi = commonFunctions.formatDate(new Date(parseInt(response.data.BiletTarihi.substr(6))));
}
$scope.CurrencyId = response.data.CurrencyId;
$scope.MusteriId = response.data.MusteriId;
$scope.PAID_EUR = response.data.PAID_EUR;
$scope.PAID_TL = response.data.PAID_TL;
$scope.PAID_USD = response.data.PAID_USD;
$scope.ServisIstiyorMu = response.data.ServisIstiyorMu;
$scope.TOTAL = response.data.TOTAL;
$scope.TourId = response.data.TourId;
$('#modal').modal('show');
});
$http.get('/Bilet/GetMusteriSelectList')
.then(function (response) {
console.log(response.data);
$scope.MusteriList = response.data;
});
};
};
app.controller('BiletController', ['$scope', '$http', 'commonFunctions', biletController]);
}());