Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS$destroy()方法don';t工作_Angularjs_Destroy - Fatal编程技术网

AngularJS$destroy()方法don';t工作

AngularJS$destroy()方法don';t工作,angularjs,destroy,Angularjs,Destroy,我试图在控制器中销毁一个作用域,但在销毁作用域后,它是可访问的,为什么 myApp.controller('modalCtrl', ['$scope', function($scope){ $scope.test = 'ha ha ha'; console.log($scope.test); // it laughs $scope.$destroy(); console.log($scope.test); // it laughs again :/ }])

我试图在控制器中销毁一个作用域,但在销毁作用域后,它是可访问的,为什么

myApp.controller('modalCtrl', ['$scope', function($scope){

    $scope.test = 'ha ha ha';
    console.log($scope.test);  // it laughs
    $scope.$destroy();
    console.log($scope.test);  // it laughs again :/

}]);

它与$digest和计时有关吗?

$destroy做两件事:

  • 在那个范围内广播$destroy
  • 将自己从其父级和兄弟级的链接列表中删除(不对其子级进行更改,它们只是留给垃圾收集)

所以你可以说这确实是一个时间问题。您的作用域将被销毁,但您不知道它将在何时被垃圾回收。您知道的是,该作用域不再可以从父作用域访问,并且出于所有意图和目的,应将其视为“死”。

@MajoB有人删除了他的评论,他是。@user3786285$scope.$destroy()