b**********1 发帖数: 215 | 1 一道Javascript Angularjs 问题:
js:
$scope.a =[];
$scope.displayFiles = function(files) {
for (var i = 0; i < files.length; i++) {
filesName.push(files[i].name);
$http({
method: ,
url: ,
headers: { },
data: { },
cache: false
}).then(function (response) {
$scope.a.push(response.data.link);
console.log($scope.a); // 结果正确,有值
});
}
}
HTML:
{{a.length}}
但是在HTML 里,{{a.length}} 是 0. 请教一下,如何把response的值,传递出去到
global variable. 多谢了 |
P*******o 发帖数: 3165 | 2 第二个log最先打印 a还没来得及赋值。
[在 bigpanda2011 (panda) 的大作中提到:]
:一道Javascript Angularjs 问题:
:js:
: $scope.a =[];
: $scope.displayFiles = function(files) {
: for (var i = 0; i < files.length; i++) {
: filesName.push(files[i].name);
: $http({
: method: ,
: url: ,
: headers: { },
:.......... |
b**********1 发帖数: 215 | 3 但是好像 不能把 a 的值 传递出来,作为全局变量。 所以在HTML 取不出来。不知道
为什么 |
P*******o 发帖数: 3165 | 4 应该能显示吧 不行单独吧 len 作为一个 scope的变量试试
[在 bigpanda2011 (panda) 的大作中提到:]
:但是好像 不能把 a 的值 传递出来,作为全局变量。 所以在HTML 取不出来。不知道
:为什么 |
b**********1 发帖数: 215 | |
h***n 发帖数: 1600 | 6 你是js function call 以后再load html吗? |
b**********1 发帖数: 215 | |