I know I can create a reference to my component in my view model like this:
.html:
board.defaultAxes.y
.ts:
<template>
<mdfield view-model.ref="ref"></mdfield>
</template>
This works, but what is the syntax if I'm creating the components dynamically? Like this:
export class Vm {
ref: any;
test(){
console.log(this.ref);
}
}
I guess I want to add them to an array in my viewmodel for later reference, but how?
答案 0 :(得分:1)
$index
为您提供repeat.for
的当前索引。因此,如果要将视图模型引用添加到数组中:
<div repeat.for="field of fields">
<mdfield view-model.ref="refArray[$index]"></mdfield>
</div>