我有以下HTML:
<select class="selectpicker" id="inputSystemLoggingId"
data-html="true" ng-init="initDataSources()" ng-options="a.id for a in systemLoggingIds"
ng-model="systemLoggingId">
</select>
以及以下控制器:
$scope.systemLoggingId = "4";
$scope.systemLoggingIds = [{"id":"4"}];
$scope.initDataSources = function() {
$http({
method: 'get',
url: '/amenityLogging/getSystemLoggingIds'
}).success(function (listSystemLoggingIds) {
console.log($scope.systemLoggingIds);
$scope.systemLoggingIds = [{"id":"5"}];
$scope.systemLoggingId = "5";
console.log($scope.systemLoggingIds);
$('#inputSystemLoggingId').selectpicker();
});
}
我看到我的$ scope.systemLoggingIds从4到5正确更新,但视图似乎没有得到有关新值的通知。如果我将代码移到$ http请求之外,它就可以正常工作。