2017-10-13 63 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]應該具有相同的格式。