Javascript $http.get之后未更新视图

Javascript $http.get之后未更新视图,javascript,angularjs,Javascript,Angularjs,我知道有很多关于这个的帖子,我也尝试过他们的解决方案,但仍然不起作用 基本上,我需要从数据库中获取一个国家列表,并在加载文档时将其显示在html页面上 下面是我的控制器 $scope.country_options = []; function get_countries() { var url = "/dashboard-api/api/country/"; var defer = $q.defer(); $http.get(url) .then(function(re

我知道有很多关于这个的帖子,我也尝试过他们的解决方案,但仍然不起作用

基本上,我需要从数据库中获取一个国家列表,并在加载文档时将其显示在html页面上

下面是我的控制器

$scope.country_options = [];

function get_countries() {
  var url = "/dashboard-api/api/country/";
  var defer = $q.defer();

  $http.get(url)
    .then(function(response) {
      defer.resolve(response.data.result);
    });

  return defer.promise;
}

function init() {
  var promise = get_countries();
  promise.then(function(data) {
    $scope.country_options = data;
  })
  console.log($scope.country_options);
}

init();
在我的html页面上

<input class="form-check-input" type="checkbox" ng-repeat="item in country_options" value="item.country_code"
       ng-model="country[item.country_code]">
&nbsp;{{item.name}}
非常感谢你的帮助! 谢谢大家!

尝试使用:

$timeout( function(){ 
   $scope.country_options = data
}, 0);
输入值

value="{{item.country_code}}"
通过以下方式绑定文本框:

<input type ="text" ng-bind="item.country_code" />
or
<input type="text" ng-value="item.country_code" />
or
<input type="text" value="{{item.country_code}}" />
or
<input type="text" ng-model="item.country_code" />

您需要使用$scope.$apply函数,因此将$scope.country\u options=数据行替换为以下代码

$scope.$applyfunction{ $scope.country_options=数据
};到底是什么问题?您预期会发生什么以及实际会发生什么?共享您的国家/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区/地区。如果一切正常,您可以在$scope.country\u options=数据行后尝试$timeoutAdd$scope.$apply并重试