在同一个受控变量中获取 $scope.data 的值 [英] get the value of $scope.data in a variable in same controlled
本文介绍了在同一个受控变量中获取 $scope.data 的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码有点东西
$scope.data = {};
var init = function () {
$http.post('views/Report.aspx/GetMailReport', {})
.success(function (data, status, headers, config) {
$scope.data = JSON.parse(data.d);
})
.error(function (data, status, headers, config) {
$scope.data = status;
})
};
init();
var data = $scope.data;
但 var 数据返回空 {}
But the var data is returning empty {}
推荐答案
如果你想要一个副本,你应该按照下面的方式做... 由于 http 调用是异步的,你在成功回调方法中分配
If you want a copy you should do as below... As the http call is asynchronous you assign inside the success callback method
$scope.data = {};
var data;
var init = function () {
$http.post('views/Report.aspx/GetMailReport', {}) .success(function (data, status, headers, config) {
$scope.data = JSON.parse(data.d);
data = $scope.data;
}) .error(function (data, status, headers, config) {
$scope.data = status;
}) };
init();
这是我创建的小提琴的链接.
Edited: Here is the link to a fiddle that I have created.
这篇关于在同一个受控变量中获取 $scope.data 的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文