首页 文章

angular-cdk的数据源可以与md-select一起使用吗?

提问于
浏览
0

我正在使用Angular 4和Angular Material 2 (2.0.0-beta8)的当前测试版 .

材料's table component is built on top of the CDK data-table. As such, it'很容易连接一个后端,它将调用数据的服务/ apis,它实现了使用RxJS Observables的所有连接 . (见demo here . )

我想弄清楚的是,如果我可以使用@ angular / cdk中的相同 DataSource 接口并使用它来填充一堆 md-select 元素 .

像这样的事情:

<md-select class="col-lg-4" placeholder="Product" [dataSource]="configData">
  <md-option *ngFor="let product of products" [value]="product.id">{{product.display_name}}</md-option>
</md-select>

这不起作用,因为 md-select 没有 dataSource 属性 . 我可以在 md-select 上使用类似的界面或属性吗?我要做的是不必重新实现md-table / dataSource实现所使用的所有Observable和其他反应功能 .

1 回答

  • 0

    我不知道,现在你让我考虑尝试订阅DataSource上的 connect() 方法 . 就像是:

    <md-option *ngFor="let product of configData.connect() | async" ...
    

    假设您的DataSource.connect返回一个Observable.merge,就像在当前的官方文档中那样,那就行了 .

相关问题