2016-04-27 56 views
2

我使用兌現,CSS angular2-兌現兌現,CSSangular2工作。一切工作正常,即使正常的選擇組件問題是與多個選擇它不呈現動態值,我不明白,如果它的初始化對象或其他東西的問題,因爲它適用於正常的選擇,但如果我添加靜態選項和渲染後,如果我點擊該選項,然後更改事件被調用,然後如果我再次單擊它,所有這些動態值將被添加到組合多選擇與angular2沒有渲染的動態值

以下是我的代碼,但如果沒有任何適當的解決方案,我可以使用任何解決方法或除materialize-css之外的任何其他框架,它經過測試並適用於angular2。

<div class="form-group"> 
      <!--if i remoe multiple it works--> 
      <select 
        materialize="material_select" 
        multiple 
        (ngModelChange)="change($event)" 
        [ngModel]="prodmodel.CategoryId" 
        ngControl="CategoryId" #catid="ngForm"> 
       <!--This options are not rendering--> 
       <option *ngFor="#p of categories" 
         [value]="p.id"> 
        {{p.CategoryTitle}} 
       </option> 
       <!--This option will render and if i click it above options will render too but not in oproper way--> 
       <option value="0">chhose</option> 
      </select> 
      <label>select Category </label> 
     </div> 

我的函數來獲取類

getCategories() { 
    this._Categories.getCategories() 
     .subscribe(
     Categories=> this.Categories= Categories, 
     error => this.errorMessage = <any>error); 
    } 
+0

哪裏了'categories'值來從? –

+0

你可以嘗試用這個Plunker https://plnkr.co/edit/sQGRzC?p=preview重現嗎? –

+0

嗨..還沒用過plunkr ..我怎麼能在那個plunkr中添加materialize-css和angular2-materialize? – noobProgrammer

回答

3

這與angular2,物質化的最新版本,現在解決了。見錯誤,並在這裏修復細節:https://github.com/InfomediaLtd/angular2-materialize/issues/21

這是你如何觸發更新選擇選項元素(使用materializeSelectOptions):

<select materialize="material_select" [materializeSelectOptions]="selectOptions"> 
 
    <option *ngFor="let option of selectOptions" [value]="option.value">{{option.name}}</option> 
 
</select>