gpt4 book ai didi

javascript - $http.get 之后 View 未更新

转载 作者:行者123 更新时间:2023-12-03 02:08:41 26 4
gpt4 key购买 nike

我知道有很多关于此问题的帖子,我已经尝试过他们的解决方案,但仍然不起作用。

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

下面是我的 Controller

$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}}"

通过以下方式绑定(bind)文本框:

<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" />

关于javascript - $http.get 之后 View 未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49677971/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com