2017-10-13 70 views
0

我不断收到以下控制台错误:尝试差异''的错误。只有阵列和iterables允许

Error trying to diff 'Paul'. Only arrays and iterables are allowed 

HTML:

<fieldset class="one-quarter sm-padding"> 
    <label>Occupation</label> 
    <select name="occupations" 
      [(ngModel)]="occupations" 
      (ngModelChange)="showValuePromptText('Occupation', $event)"> 
     <option *ngFor="let occupation of occupations" 
       [value]="occupation"> 
      {{occupation}} 
     </option> 
    </select> 
</fieldset> 

TS:

import { Component } from '@angular/core'; 
import { PromptService } from '../../services/prompt.service'; 
import { IPromptText } from "../../models/IPromptText"; 

@Component({ 
    selector: 'fact-find', 
    templateUrl: './factfind.component.html', 
    styleUrls: ['./factfind.component.css'], 
    providers: [PromptService] 
}) 

export class FactFindComponent { 
    promptTexts: IPromptText[]; 
    currentPromptText : string; 

    showDefaultPromptText(fieldName: string) { 
     if (fieldName != null) { 
      this.promptService.fetchPrompts(fieldName, '').subscribe(
       (data) => this.currentPromptText = data 
      ); 
     } 
    } 

    showValuePromptText(fieldName: string, fieldValue: string) { 
     if (fieldValue != null) { 
      this.promptService.fetchPrompts(fieldName, fieldValue).subscribe(
       (data) => this.currentPromptText = data 
      ); 
     } 
    } 

    occupations: string[] = ["John", "Paul", "George", "Ringo"]; 
} 

如果有人可以提供一些线索点亮我如何解决这个问题将不胜感激。

回答

0
[(ngModel)]="occupations[0]" 

[(ngModel)][value]应该具有相同的格式。