Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 多功能<;输入>;角度场_Angular_Typescript_Ngfor - Fatal编程技术网

Angular 多功能<;输入>;角度场

Angular 多功能<;输入>;角度场,angular,typescript,ngfor,Angular,Typescript,Ngfor,我目前正在尝试为Angular 9中的每个字母输入一个不同的输入。我目前似乎遇到的问题是变化检测。我认为这两种方法是相互冲突的更改。当我在我的*ngFor中使用自定义的trackBy时,subscribe()from@ViewChildren()不会更新,但我需要trackBy来防止一个框中的更改在另一个框中传播的各种问题。我可以使用自定义trackBy功能,但它无法从我的组件访问数据。以下是我的组件: @组件({ 选择器:“应用程序多字段”, templateUrl:“./multi-fiel

我目前正在尝试为Angular 9中的每个字母输入一个不同的输入。我目前似乎遇到的问题是变化检测。我认为这两种方法是相互冲突的<代码>更改。当我在我的
*ngFor
中使用自定义的
trackBy
时,subscribe()from
@ViewChildren()
不会更新,但我需要
trackBy
来防止一个框中的更改在另一个框中传播的各种问题。我可以使用自定义
trackBy
功能,但它无法从我的组件访问数据。以下是我的组件:

@组件({
选择器:“应用程序多字段”,
templateUrl:“./multi-fields.component.html”,
样式URL:['./多个字段.component.css'],
供应商:[
{
提供:NG_值访问器,
多:是的,
useExisting:forwardRef(()=>MultipleFieldsComponent),
},
],
})
导出类MultipleFieldsComponent
实现OnInit、AfterViewInit、ControlValueAccessor{
@Input()numFields:number=6;
@ViewChildren('input',{read:ElementRef})输入:QueryList<
ElementRef
>;
字段:字符串[];
onChange:any=()=>{};
onTouch:any=()=>{};
ngAfterViewInit(){
this.inputs.changes.subscribe((下一步:QueryList)=>{
让val=next.map((el)=>el.nativeElement.value).join(“”);
这个。onChange(val);
这个.onTouch(val);
});
}
恩戈尼尼特(){
this.fields=数组(this.numFields).fill(“”);
}
trackArray(索引,项){
收益指数;
}
writeValue(值:字符串){
如果(value.length==this.numFields)this.fields=value.split(“”);
}
注册变更(fn:任何){
this.onChange=fn;
}
注册人(fn:任何){
this.onTouch=fn;
}
}
以下是组件的模板:



我希望能够检测到
字段[]
数组中的任何更改,然后使用联接值调用
onChange()
onTouch()
,以便能够在组件使用上使用
[(ngModel)]
。任何帮助都将不胜感激。谢谢大家!

我可能不明白你想做什么,但你为什么不使用角度变化呢

<input *ngFor="let item of fields" (change)="itemChanged(item)">