小编Ind*_*j26的帖子

ngFor 中调用的方法多次被触发

我正在调用 ngFor 中的一种方法来获取输入的标签,即使在 ngFor 中有 2 个项目,它也会触发 8 次。它应该只被调用两次。多次被调用的原因可能是什么?

<form [formGroup]="parentForm">
   <div formGroupName="child">
    <ng-container *ngFor="let item of parentForm.get('child').controls | keyvalue; let i = index">
      <div class="form-group">
      <label>{{getLabel(item.key)}} {{i}} </label>
      <input type="text" [formControlName]="item.key">
      </div>
    </ng-container>
   </div>
  </form>   
Run Code Online (Sandbox Code Playgroud)
  getLabel(item) {
     console.log('trigger item') // its get printed in console for 8 times
  if(item == 'data')  { 
    return 'Your Data' 
  } 
  return 'Your Name'
  }
Run Code Online (Sandbox Code Playgroud)

游乐场:https://stackblitz.com/edit/angular-ivy-hnaegv ?file=src%2Fapp%2Fapp.component.html

angular angular9

5
推荐指数
1
解决办法
4022
查看次数

查询对象 mongoose 的嵌套数组

我想在嵌套对象游乐场中使用 Alexa 查找名称:https://mongoplayground.net/p/rqYQtf0liaX

[
  {
    item: "journal",
    instock: [
      {
        warehouse: "A",
        qty: 5,
        items: null
      },
      {
        warehouse: "C",
        qty: 15,
        items: [
          {
            name: "alexa",
            age: 26
          },
          {
            name: "Shawn",
            age: 26
          }
        ]
      }
    ]
  }
]
Run Code Online (Sandbox Code Playgroud)

到目前为止我已经尝试过,这返回没有找到文档

db.collection.find({
  "instock.items": {
    $elemMatch: {
      name: "Alexa"
    }
  }
})
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb mongodb-query

5
推荐指数
1
解决办法
7453
查看次数

3
推荐指数
2
解决办法
1070
查看次数

javascript对象[es6]中的模板文字

我如何将对象值分配给对象的其他键。我试过了,但是我无法得到所有未定义的信息。

let test = {
 id:1,
 name:this.test.id
}

let test2 = {
 id:1,
 name:`hello, ${this.id}`
}

console.log(test)
console.log(test2);
Run Code Online (Sandbox Code Playgroud)

javascript typescript ecmascript-6

1
推荐指数
1
解决办法
37
查看次数