Angular JS 打破 ForEach [英] Angular JS break ForEach

查看:22
本文介绍了Angular JS 打破 ForEach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有角度的 foreach 循环,如果我匹配一个值,我想中断循环.以下代码不起作用.

I have an angular foreach loop and i want to break from loop if i match a value. The following code does not work.

angular.forEach([0,1,2], function(count){
  if(count == 1){
    break;
  }
});

我怎样才能得到这个?

推荐答案

没有办法做到这一点.请参阅 https://github.com/angular/angular.js/issues/263.根据您在做什么,您可以使用布尔值来避免进入循环体.类似的东西:

There's no way to do this. See https://github.com/angular/angular.js/issues/263. Depending on what you're doing you can use a boolean to just not going into the body of the loop. Something like:

var keepGoing = true;
angular.forEach([0,1,2], function(count){
  if(keepGoing) {
    if(count == 1){
      keepGoing = false;
    }
  }
});

这篇关于Angular JS 打破 ForEach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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