materialize-css 中的多个 select with angular2 不呈现动态值
Multiple select in materialize-css with angular2 not rendering dynamic values
我正在使用 angular2-materialize 和 materialize-css 来处理 angular2。一切 即使是正常的 select 组件 也能正常工作。
问题出在多个 select 它不呈现动态值,我不明白这是不是问题初始化对象或其他东西,因为它适用于正常的 select 但是如果我添加静态选项并且在渲染后如果我单击该选项然后 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);
}
现在使用最新版本的 angular2-materialize 解决了这个问题。在此处查看错误和修复详细信息:https://github.com/InfomediaLtd/angular2-materialize/issues/21
这是触发 select 选项元素更新的方法(使用 materializeSelectOptions):
<select materialize="material_select" [materializeSelectOptions]="selectOptions">
<option *ngFor="let option of selectOptions" [value]="option.value">{{option.name}}</option>
</select>
我正在使用 angular2-materialize 和 materialize-css 来处理 angular2。一切 即使是正常的 select 组件 也能正常工作。 问题出在多个 select 它不呈现动态值,我不明白这是不是问题初始化对象或其他东西,因为它适用于正常的 select 但是如果我添加静态选项并且在渲染后如果我单击该选项然后 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);
}
现在使用最新版本的 angular2-materialize 解决了这个问题。在此处查看错误和修复详细信息:https://github.com/InfomediaLtd/angular2-materialize/issues/21
这是触发 select 选项元素更新的方法(使用 materializeSelectOptions):
<select materialize="material_select" [materializeSelectOptions]="selectOptions">
<option *ngFor="let option of selectOptions" [value]="option.value">{{option.name}}</option>
</select>