Angular ForEach in Angular4/Typescript?

前端 未结 4 956
说谎
说谎 2021-02-18 19:49

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 contr

相关标签:
4条回答
  • 2021-02-18 20:18
    arrayData.forEach((key : any, val: any) => {
                            key['index'] = val + 1;
    
                            arrayData2.forEach((keys : any, vals :any) => {
                                if (key.group_id == keys.id) {
                                    key.group_name = keys.group_name;
                                }
                            })
                        })
    
    0 讨论(0)
  • 2021-02-18 20:20

    you can try typescript's For :

    selectChildren(data , $event){
       let parentChecked : boolean = data.checked;
       for(let o of this.hierarchicalData){
          for(let child of o){
             child.checked = parentChecked;
          }
       }
    }
    
    0 讨论(0)
  • 2021-02-18 20:22

    In Typescript use the For Each like below.

    selectChildren(data, $event) {
    let parentChecked = data.checked;
    for(var obj in this.hierarchicalData)
        {
            for (var childObj in obj )
            {
                value.checked = parentChecked;
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-18 20:29

    in angular4 foreach like that. try this.

     selectChildren(data, $event) {
          let parentChecked = data.checked;
           this.hierarchicalData.forEach(obj => {
              obj.forEach(childObj=> {
                value.checked = parentChecked;
             });
          });
        }
    
    0 讨论(0)
提交回复
热议问题