Simplifying expression in iterator biding to ngModel

南楼画角 提交于 2020-03-05 06:04:20

问题


I have arrived at a lengthy syntax iterating over data[areaId].main.points. Since the data is bound via [(ngModel)], it looks atrociously in my opinion. Something like this.

<div *ngFor="let item of data[areaId].main.points; let index = index; let ..." ...>
  <input [(ngModel)]="data[areaId].main.points[index].e" ... >
  <input [(ngModel)]="data[areaId].main.points[index].n" ... >
  ...
</div>

Usually, when the syntax gets ugly, it's a strong indication that the design sucks and should be simplified. Not always. But in most cases. So I wonder if there's a syntax setting the data-main-points thing to something locally defined and shorter. One option might be to declare an auxilliary field in the model only keeping a portion of the whole data and bind to it. However, I sense that there's a better way to approach it.

How should I simplify the expression so that the iterator can reder and the ngModel can keep an eye on its changes?

来源:https://stackoverflow.com/questions/60027413/simplifying-expression-in-iterator-biding-to-ngmodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!