【发布时间】:2016-04-27 11:01:50
【问题描述】:
我正在使用 angular2-materialize 和 materialize-css 来处理 angular2。 即使是普通的选择组件也能正常工作。 问题在于多选 它不呈现动态值,我不明白是初始化对象的问题还是其他问题,因为它适用于正常选择,但如果我添加静态选项并在渲染后单击该选项,则调用 change 事件,然后如果我再次单击它,所有这些动态值都会添加到组合中。
以下是我的代码,但如果没有任何合适的解决方案,我可以使用任何 workaround 或任何其他框架,而不是 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);
}
【问题讨论】:
-
categories值从何而来? -
你能尝试用这个 Plunker plnkr.co/edit/sQGRzC?p=preview 复制吗?
-
嗨.. 还没有使用 plunkr.. 我如何在那个 plunkr 中添加 materialize-css 和 angular2-materialize?
-
我不知道 materialize-css 和 angular2-materialize :-/
-
非常感谢,但是它和 angular2-materialize 本身的问题和那个人正在 github 上工作。当它完成当前的解决方法是 $('#select') 时,我会给出答案。材料选择()
标签: typescript angular materialize multiple-select