gpt4 book ai didi

javascript - Angularjs变量在 Controller 中获取http不可见

转载 作者:行者123 更新时间:2023-11-28 06:47:00 25 4
gpt4 key购买 nike

Controller 中不可见的变量是否仅在 html 中可见?

app.controller('Ctrl', function ($scope, $http) {
var request = $http({
method: "get",
url: "xxxxxx.php"
})
.success(function(gl){
$scope.users = gl;
});

// Initial data
var e = request.users;
$scope.chartData = [
['Coo',e],
];
});

最佳答案

$http.success内部构造$scope.chartData,就像

var request = $http({
method: "get",
url: "xxxxxx.php"
})
.success(function (gl) {
$scope.users = gl;

//initialize your chartData here or
//if you have already defined chartData then just push the new object
$scope.chartData = [['Coo', $scope.users], ];
});

// Initial data

//this will not work because request is a promise object
/*var e = request.users;
$scope.chartData = [
['Coo', e],
];*/

关于javascript - Angularjs变量在 Controller 中获取http不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33327435/

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