在控制器中的$ scope上设置和获取变量

时间:2015-01-19 18:09:36

标签: angularjs

在我的角度应用程序的控制器中,我将范围变量设置为false,如此

$scope.stop = false; 

当我按下UI中的按钮时,我将$ scope.stop值设置为由按钮单击触发的函数内的

  $scope.stopRunningThing = function(){
        $scope.stop = true; 
   }

在继续之前,我应该提一下,这似乎已成问题,因为我不知道哪个优先,控制器中的$ scope.stop,或控制器中的函数内部。

接下来,在另一个函数中,我检查看看$ scope.stop的值,但是,即使我在函数内部将变量设置为true,下面的代码总是在运行,好像它始终为false

if ($scope.stop == true){
    console.log("Never getting run")

}else {
    console.log("always getting run");
}

在这种情况下,您能解释一下我应该如何设置并检查$ scope上变量的值?

更新

$ scope.start首先在程序中运行,并且它有一个永远运行的循环,我希望$ scope.stop检查运行的代码突破循环,但$ scope.stop检查不是按预期工作

   $scope.start = function() {

   ...this check is wrapped in some code that runs continously...
        if ($scope.stop == true){
        console.log("Never getting run")
        ...this is the code that will break out of the continuous code if $scope.stop == true...

       }else {
        console.log("always getting run");

       }

    }

0 个答案:

没有答案
相关问题