本文介绍了如何在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

推荐答案







什么我试过了:





What I have tried:

<pre lang="Javascript">
var getlockerbalance=function(){


这篇关于如何在angularjs中从外部访问函数内部的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:56