简体   繁体   English

如何限制 ngModel 更改对 angular7 中其他内部 ng-template 的影响?

[英]How to restrict ngModel changes effect to other inside ng-template in angular7?

在此处输入图片说明

This is my code这是我的代码

 <ng-template #rowDetailsTmpl let-row="row"> <div class="row" style="padding: 10px 30px;"> <div class="col-sm-5 form-group"> <label> Add Operator </label> <input type="string" id={{row.DeskId}} name={{row.DeskId}} (ngModelChange)="onChangeOperator($event)" class="form-control" placeholder="Search Operator" [(ngModel)]="selectedOperatorEmail"> </div> @ViewChild('rowDetailsTmpl', { static: true }) rowDetailsTmpl: TemplateRef<any>; this._dataTableService.rowDetailsTemplate = this.rowDetailsTmpl;

In my code input text field using inside ng-template , i set id and name dynamically , but when i change value in textbox it automatically reflect to other input fields.在我使用 ng-template 内部的代码输入文本字段中,我动态设置了 id 和 name,但是当我更改文本框中的值时,它会自动反映到其他输入字段。 so how to solve this problem in angular7.那么如何在angular7中解决这个问题。

in component define the model like array:在组件中定义模型,如数组:

selectedOperatorEmail: Array<any> = [];

in html define ngModel define like this:在 html 中定义 ngModel 定义如下:

[(ngModel)]="selectedOperatorEmail[row.DeskId]"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM