Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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/8.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 compareWith不选择_Angular_Typescript_Compare - Fatal编程技术网

Angular compareWith不选择

Angular compareWith不选择,angular,typescript,compare,Angular,Typescript,Compare,我有一个选择选项与compareWith,但它不是选择下拉列表中的记录 <select class="form-control" name="selectAnswer" [(ngModel)]="Result.answers[i]" [compareWith]="compareFn"> <option [ngValue]="answer" *ngFor="let answer of QuestionOption.Answers">{{answer.description

我有一个选择选项与compareWith,但它不是选择下拉列表中的记录

<select class="form-control"  name="selectAnswer" [(ngModel)]="Result.answers[i]" [compareWith]="compareFn">
<option [ngValue]="answer" *ngFor="let answer of QuestionOption.Answers">{{answer.description}}</option>
在console.log中,我收到true、false、false。。。 因此,如果c1.id==c2.id,函数返回的结果似乎非常好

但是 在下拉列表中,未选择记录。它只是空着

我错过了什么


一切似乎都很好,只是选择不起作用。根本原因可能是什么?

不,对不起,这是在将代码复制到StackOverflow的过程中出现的一个输入错误。我发现了这一点:他们引用了:注意:我们侦听“更改”事件,因为Firefox和IE中的SELECT不会触发“输入”事件。我使用的是Firefox。这可能是问题的根本原因吗?不,对不起,这是在将代码复制到StackOverflow的过程中出现的一个输入错误。我发现了这一点:他们引用了:注意:我们侦听“更改”事件,因为Firefox和IE中的SELECT不会触发“输入”事件。我使用的是Firefox。这可能是问题的根本原因吗?
compareFn(c1: any, c2: any): boolean {
      console.log(c1 && c2 ? c1.id === c2.id : c1 === c2);
         return c1 && c2 ? c1.id === c2.id : c1 === c2;
    }