简体   繁体   English

角度5:* ng的数据用于单击单选按钮后进行更改

[英]Angular 5: Data of *ngFor changing after a click on a radio button

So the issue is , I have an array in *ngFor inside a <tr> . 所以问题是,我在<tr> *ngFor有一个数组。 Inside the row I have multiple <td> , first one of which has a radio button. 在行中,我有多个<td> ,其中第一个具有单选按钮。 When the page is loaded the table is rendered normally. 加载页面后,表将正常呈现。 After I click on the radio button I get the 单击单选按钮后,

error: Error trying to diff 'on'. 错误:尝试差异“打开”时出错。 Only arrays and iterables are allowed. 仅允许数组和可迭代。

As I click the radio button, I have also console.log the data itself, the data is viewed normally. 当我单击单选按钮时,我也有console.log数据本身,可以正常查看数据。 But the second time I click it the data is 'on'. 但是,第二次单击它时,数据已打开。

Basically the data is changing after the first click on the radio button. 基本上,第一次单击单选按钮后,数据就会更改。

This is the Code : 这是代码:

<tr *ngFor="let i of mpFASetupList" [style.background-color]="checkFlag ? 'yellow' : 'white'">
    <td class="data" id="zero">
      <input id="faRadioBtn" type="radio" name="anyName"  (click)="onSelectFaSetup(i)">
    </td>
</tr>

TS Code: TS代码:

onSelectFaSetup(setup){
    console.log('Fa List' , this.mpFASetupList);
    this.isFaSelected = true;
    this.isCustSelected = false;
    console.log('fa before ' , setup);
    this.dashboardId = setup.mainDashboardId;
    console.log('fa after ' , setup);
}

There are the error messages : 有错误消息:

First Click : "Fa List" is the data. 首先单击: “ Fa List”就是数据。 (image) (图片)

Second Click : "Fa List" is the data. 第二次单击: “ Fa List”为数据。 (image) (图片)

As you can see , the data "Fa List" is changing after the click. 如您所见,单击后数据“ Fa List”正在更改。 Any idea guys why angular is behaving this way ? 有人知道为什么angular会采用这种方式吗?

Edit 1 : This is the mpFASetupList data : 编辑1:这是mpFASetupList数据:

mpFASetupList : [{internalCode: 0, authFlag: false, mainDashboardId: 0, validateStatusFlag: false, statusFlag: false}] mpFASetupList:[{internalCode:0,authFlag:false,mainDashboardId:0,validateStatusFlag:false,statusFlag:false}]

I found the reason for this behavior , the <table> tag in which the <tr> tag was placed had a name , [(ngModel)] and ngDefaultControl . 我发现了这种现象的原因,放置<tr>标记的<table>标记具有name [(ngModel)]ngDefaultControl

Hence it was behaving like that. 因此,它的行为是这样的。 After trimming down these unnecessary attributes , it is behaving as expected. 修剪掉这些不必要的属性后,它的行为符合预期。

Well Fa List is a string "on" after you clicked the radio button. 单击单选按钮后,Fa Fa List是字符串“ on”。 Since i don't know what onSelectFaSetup does i can only assume that you change the mpFASetupList to the string "on", which the *ngFor directive can't loop because it's not an array. 因为我不知道onSelectFaSetup是什么,所以我只能假设您将mpFASetupList更改为字符串“ on”,* ngFor指令不能循环,因为它不是数组。 If you post the method i might help a bit more 如果您发布方法,我可能会提供更多帮助

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

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