如何在angularjs中从外部访问函数内部的变量
问题描述:
我在控制器内部有两个函数,但我无法在函数外部打印变量。我们如何解决问题?
I have two functions inside the controller ,But i couldn't print variables outside the function .How can we fix the problem?
var getlockerbalance=function(){
$http.get("php/selectLOCKERBALANCE.php")
.success(function(lockerbalance){
$scope.lockerbalance1=lockerbalance;
var lastlockerbalance=$scope.lockerbalance1[0].LOCKERBALANCE;
console.log(lastlockerbalance);
})
}
我的尝试:
What I have tried:
<pre lang="Javascript">
var getlockerbalance=function(){
$http.get("php/selectLOCKERBALANCE.php")
.success(function(lockerbalance){
$scope.lockerbalance1=lockerbalance;
var lastlockerbalance=$scope.lockerbalance1[0].LOCKERBALANCE;
console.log(lastlockerbalance);
})
console.log(lastlockerbalance);
错误表示未定义的lastlockerbalance
The error says that lastlockerbalance in undefined
答
http.get ( php / selectLOCKERBALANCE.php)
.success( function (lockerbalance){
http.get("php/selectLOCKERBALANCE.php") .success(function(lockerbalance){
scope.lockerbalance1 = lockerbalance;
var lastlockerbalance =
scope.lockerbalance1=lockerbalance; var lastlockerbalance=
scope.lockerbalance1 [ 0 ]。LOCKERBALANCE;
con鞋底跨度> .log中(lastlockerbalance);
})
}
scope.lockerbalance1[0].LOCKERBALANCE; console.log(lastlockerbalance); }) }
什么我试过了:
What I have tried:
<pre lang="Javascript">
var getlockerbalance=function(){