我正在调用 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
我想在嵌套对象游乐场中使用 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) 我如何将对象值分配给对象的其他键。我试过了,但是我无法得到所有未定义的信息。
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) angular ×1
angular9 ×1
ecmascript-6 ×1
javascript ×1
mongodb ×1
mongoose ×1
rxjs ×1
rxjs6 ×1
typescript ×1