2017-11-06 6 views
0

私はカスタムコンテンツのドロップダウンを実装しています。正しく動作していない。 selectedTestTypeの値は設定されず、onChangeTestTypesの値はundefinedとなります。PrimeNGでカスタムコンテンツのドロップダウンが機能しませんか?

<p-dropdown name="classTestTypeCombobox" 
      [options]="TestTypes" [(ngModel)]="selectedTestType" 
      [style]="{'width':'150px'}" filter="filter" 
      [disabled]="this.isProdCodeDisabled" 
      appendTo="body" 
      required 
      #classTestTypeCombobox="ngModel" 
      (ngModelChange)="onChangeTestTypes($event)"> 
    <ng-template let-TestType pTemplate="item"> 
     <div class="ui-helper-clearfix" style="position: relative;height: 25px;"> 
      <div>{{TestType.descLong}}</div> 
     </div> 
    </ng-template> 
</p-dropdown> 

TestTypesは、次のメンバを持つクラスオブジェクトの配列です。

id: number; 
classificationCode: string; 
descLong: string; 
classificationParent: string; 
codeType: number; 

onChangeTestTypes(TestType) { 
    this.selectedTestTypeDesc = this.TestTypes.filter(x => x.priceCode == TestType)[0].descLong; 
    this.price.Type = this.TestTypes.filter(x => x.priceCode == TestType)[0].Type; 
} 
+0

"TestType"フィールドの宣言とその値の挿入方法を含めることはできますか? –

答えて

-1

ドロップダウンリストに表示するフィールドの名前にoptionLabelを使用します。あなたが使用したい場合たとえばclassificationCode

<p-dropdown name="classTestTypeCombobox" 
      [options]="TestTypes" [(ngModel)]="selectedTestType" 
      [style]="{'width':'150px'}" filter="filter" 
      [disabled]="this.isProdCodeDisabled" 
      optionLabel="classificationCode" 
</p-dropdown> 

はoptionLabelが割り当てられた値は、カスタムオブジェクトのフィールドの名前は簡単ですまた、[]必要がないことを確認します。

+0

optionLabelには1つのプロパティしか表示されないので、ここでカスタムコンテンツを表示しようとしているので、これは機能しません。私も同じ問題を抱えています。 – Ziggler

関連する問題