typescript - 具有angular2的materialize-css中的多个选择不呈现动态值

标签 typescript angular materialize multiple-select

我正在使用 angular2-materializema​​terialize-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

这是触发更新以选择选项元素的方法(使用 ma​​terializeSelectOptions):

<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/

相关文章:

javascript - 如何在 Angular 中使用 ngFor 遍历对象属性

javascript - 如何将 Electron ipcRenderer 集成到基于 TypeScript 的 Angular 2 应用程序中?

angular - 是否可以在 Angular 组件中验证服务调用?

angular - 如何在静态函数中调整大小/更改时将 gridster-item 保存在数据库中?

html - z-index 在 material side-nav 上无法正常工作

html - 使用搜索栏和自动完成显示错误(具体化 CSS)

javascript - 如何指示从对象调用的绑定(bind)成员函数的上下文类型?

typescript - Visual Studio Code 使用 "react-jsx"作为 jsx 值与 create-react-app 的问题

Angular 通用 : How to create an app shell and only pre-render the shell?

javascript - 在实现 toast 中设计通知/警报的简洁方法