2016-04-27 33 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>