我正在使用 angular2-materialize 和 materialize-css 来处理 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);
}
最佳答案
现在使用最新版本的 angular2-materialize 解决了这个问题。在此处查看错误和修复详细信息: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>
关于typescript - 具有angular2的materialize-css中的多个选择不呈现动态值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36887895/