AngularJS事件时,模型绑定或NG重复完成? [英] AngularJS event for when model binding or ng-repeat is complete?

查看:82
本文介绍了AngularJS事件时,模型绑定或NG重复完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个大的模型,它需要几秒钟NG重复绑定模型到窗体中的所有项目。我们想证明,而它这种情况正在发生好手。是否有一些触发结合完成时,所以我们知道什么时候隐藏微调事件?

We have a large model and it takes a couple seconds for ng-repeat to bind all the items in the model to the form. We would like to show a spinner while it this is happening. Is there some event that fires when binding is complete so we know when to hide the spinner?

推荐答案

Plunkr:的http:// plnkr。 CO /编辑/ GzzTW4?p = preVIEW

使用 NG-节目的微调如果您使用的是1.2使用 NG-如果

Use ng-show on the spinner If you are using 1.2 use ng-if

<div ng-controller="Ctrl">
    <div ng-show="complete">Complete={{complete}}</div>
    <div class="thing" ng-repeat="thing in things" my-post-repeat-directive>
       thing {{thing}}
   </div>
</div>

在你的指令使用$最后一次,以确定是否渲染完成,然后改变你有可变的NG-显示/ ngif定义。

In your directive use $last to determine if rendering is done and then change the variable that you have the ng-show/ngif defined on.

function Ctrl($scope) {
  $scope.complete=false;  
  $scope.doComplete = function() {
      $scope.complete = true;
  }

  $scope.things = [
    'A', 'B', 'C'
  ];
}

angular.module('myApp', [])
  .directive('myPostRepeatDirective', function() {
    return function(scope, element, attrs) {
      if (scope.$last) {
        scope.$eval('doComplete()');
      }
    };
  });

这篇关于AngularJS事件时,模型绑定或NG重复完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆