Angular4/Typescript中的Angular ForEach? [英] Angular ForEach in Angular4/Typescript?

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

问题描述

当我搜索ngFor时,我看到了许多有关使用ngFor的答案,但我了解ngFor.我问的是Angular 1控制器中使用的angular.forEach()构造函数.这些在TS中被标记为错误,无法编译.

I see many answers about using ngFor when I search for this, but I understand ngFor. I'm asking about the angular.forEach() constructor used in my Angular 1 controllers. These are flagged as errors in TS and do not compile.

例如,我有一个嵌套循环:

For example, I have one with a nested loop:

 _this.selectChildren = function (data, $event) {
  var parentChecked = data.checked;
  angular.forEach(_this.hierarchicalData, function (value, key) {
    angular.forEach(value.children, function (value, key) {
      value.checked = parentChecked;
    });
  });
};

此构造在Angular 4的Typescript中是什么样的?

What does this construct look like in Typescript for Angular 4?

推荐答案

in angular4 foreach这样的.试试这个.

in angular4 foreach like that. try this.

 selectChildren(data, $event) {
      let parentChecked = data.checked;
       this.hierarchicalData.forEach(obj => {
          obj.forEach(childObj=> {
            value.checked = parentChecked;
         });
      });
    }

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

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