Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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
Javascript 部分函数后的重新加载_Javascript_Angularjs - Fatal编程技术网

Javascript 部分函数后的重新加载

Javascript 部分函数后的重新加载,javascript,angularjs,Javascript,Angularjs,我有一个数组中的大量数据,并希望渲染其中的所有项目。 这可能需要一段时间来渲染,因此我希望在渲染开始之前插入加载动画 代码如下所示: $scope.foo = function() { // Start loading animation $loading.start(); // Load objects into an array. These objects are // rendered by the ng-repeat directive from angul

我有一个数组中的大量数据,并希望渲染其中的所有项目。 这可能需要一段时间来渲染,因此我希望在渲染开始之前插入加载动画

代码如下所示:

$scope.foo = function() {
   // Start loading animation
   $loading.start();

   // Load objects into an array. These objects are 
   // rendered by the ng-repeat directive from angular
   $scope.array = data;
}
但是当我执行函数foo时,首先ng repeat渲染所有项目,然后加载动画开始。
如何实现反向行为(首先是加载动画,然后是ng重复渲染)?

$timeout
注入控制器的依赖项,然后将函数更改为:

$scope.foo = function() {
   // Start loading animation
   $loading.start();

   // Load objects into an array. These objects are 
   // rendered by the ng-repeat directive from angular
   $timeout(function() {
       $scope.array = data;
   });
}

超时将使视图在您开始数据处理之前刷新

向控制器的依赖项注入
$timeout
,然后将函数更改为:

$scope.foo = function() {
   // Start loading animation
   $loading.start();

   // Load objects into an array. These objects are 
   // rendered by the ng-repeat directive from angular
   $timeout(function() {
       $scope.array = data;
   });
}

超时将使视图在开始数据处理之前刷新

您可以使用$timeout来实现它。在代码集中,超时与加载持续时间

$scope.foo = function() {
  // Start loading animation
  $loading.start();

  $timeout(function() {
    // Load objects into an array. These objects are 
    // rendered by the ng-repeat directive from angular
    $scope.array = data;
  }, YOUR_LOAD_TIME);
}

不要忘了在控制器中插入$timeout。

您可以使用$timeout来实现它。在代码集中,超时与加载持续时间

$scope.foo = function() {
  // Start loading animation
  $loading.start();

  $timeout(function() {
    // Load objects into an array. These objects are 
    // rendered by the ng-repeat directive from angular
    $scope.array = data;
  }, YOUR_LOAD_TIME);
}

不要忘记在控制器中注入
$timeout

什么是$loading?您创建的服务?$loading是来自此库的服务:什么是$loading?您创建的服务?$loading是来自此库的服务:谢谢您的回答!这已经起作用了,但是在加载动画触发之前仍然有很大的延迟。你对如何解决这个问题有什么建议吗?如果你能制作一个提琴或弹琴,那就更好了。谢谢你的帮助!在创建plunkr时,我意识到,我必须设置一个超时,以便给页面时间重新加载。你的答案是正确的谢谢你的回答!这已经起作用了,但是在加载动画触发之前仍然有很大的延迟。你对如何解决这个问题有什么建议吗?如果你能制作一个提琴或弹琴,那就更好了。谢谢你的帮助!在创建plunkr时,我意识到,我必须设置一个超时,以便给页面时间重新加载。你的答案是正确的