简体   繁体   English

在angularize-css中多次选择,其中angular2不渲染动态值

[英]Multiple select in materialize-css with angular2 not rendering dynamic values

I am using angular2-materialize with materialize-css to work with angular2 . 我正在使用angular2-materializematerialize-css一起使用angular2 Everything works fine even the normal select component . 即使是正常的选择组件,一切都很好 the problem is with multiple select it doesn't render the dynamic values , I don't understand if its the issue with the initializing object or something else as it works for a normal select but if i add static options and after rendering if I click that option then change event is called and then if I click it again all those dynamic values gets added to the combo . 问题是多次选择 它不会渲染动态值 ,我不明白它是否与初始化对象或其他东西的问题,因为它适用于普通选择,但如果我添加静态选项,并在渲染后如果我点击然后调用该选项然后更改事件,然后如果再次单击它,则所有这些动态值都会添加到组合中

Below is my code but if there is not any proper solution i can work with any workaround or any other framework than materialize-css which is tested and works proper with 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>

My function to get categories : 我获取类别的功能

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

This is solved now with the latest version of angular2-materialize. 现在使用最新版本的angular2-materialize解决了这个问题。 See bug and fix details here: https://github.com/InfomediaLtd/angular2-materialize/issues/21 请在此处查看错误并修复详细信息: https//github.com/InfomediaLtd/angular2-materialize/issues/21

This is how you can trigger updates to select option elements (using materializeSelectOptions ): 这是您可以触发更新以选择选项元素的方法(使用materializeSelectOptions ):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM