【问题标题】:Multiple select in materialize-css with angular2 not rendering dynamic values使用angular2在materialize-css中进行多项选择不呈现动态值
【发布时间】:2016-04-27 11:01:50
【问题描述】:

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


【解决方案1】:

现在使用最新版本的 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 2017-12-20
    • 1970-01-01
    • 2017-07-02
    相关资源
    最近更新 更多