In AngularJS, how can I ensure code is only executed after a change to a watched property has taken full effect in the UI.

在AngularJS中,我如何确保仅在监视属性的更改在UI中完全生效后才执行代码。

For example, say that the visiblity of a loading indicator is bound to the the value of a isLoading property on a model. How can I ensure that subsequent functionality is only executed after the loading indicator has become visible?

例如,假设加载指示符的可见性绑定到模型上isLoading属性的值。如何确保仅在加载指示器可见后执行后续功能?

e.g.

例如

my-template.html

我-template.html

<my-loading-indicator ng-show="model.isLoading"></my-loading-indicator>

my-controller.js

我-controller.js

// ...
MyController.prototype.doSomething = function() {
  this.model.isLoading = true;
  // how can I guarantee that the UI is now showing the loading indicator before proceeding?
}

2 个解决方案

#1


1

You would need to use $timeout which will not be run until digest cycle completes.

您需要使用$ timeout,直到摘要周期完成才会运行。

// will start digest cycle since it is bound to `ng-show`
this.model.isLoading = true;

$timeout(function(){
   // indicator should be visible now
}[,optional delay]);

Don't forget to inject $timeout wherever you are using it

不要忘记在任何地方使用它注入$ timeout

更多相关文章

  1. JQuery Image滑块从json加载图片
  2. AngularJS我在哪里可以访问加载的控制器的范围?
  3. 选择jquery - 列表未以模态形式加载
  4. JavaScript 对象属性作实参以及实参对象的callee属性
  5. Angular 2快速入门 - 我的应用程序组件未加载
  6. 使用jackson json将属性添加到json字符串
  7. React组件的属性PropTypes
  8. 将(重度公式加载的)Excel电子表格转换为用户友好的网络计算器
  9. Nivoslider(在动态ajax内容中)不会在第一次加载时加载图像

随机推荐

  1. 在python中创建指数函数。
  2. 你怎么检查python字符串是否只包含数字?
  3. python-selenium-定位一组对象
  4. Python学习记录--关于列表和字典的比较
  5. scikit-learn:在标记化时不要分隔带连字符
  6. 分析标签集的最佳方法是什么?
  7. 学习Python爬虫(五):爬取图片
  8. python飞船游戏(三)
  9. 深度学习与计算机视觉系列(1)_基础介绍
  10. macports没有将python_select放在/ opt /