【问题标题】:Primeng: multiselect not filledPrimeng:多选未填充
【发布时间】:2019-12-24 16:36:03
【问题描述】:

我正在反对p-multiSelect 上的填充选项。

HTML 代码是:

<p-multiSelect
  name="ambits"
  [options]="scopes$ | async">
</p-multiSelect>

scopes$ 在哪里:

public scopes$: Observable<Array<ApplicationScope>>;
constructor(
    private service: AplicacionsSubcomponentService
) {
    this.scopes$ = service.getScopes()
        .pipe((take(1)));
}

不过,我的多选选项为空,Observable&lt;Array&lt;ApplicationScope&gt;&gt; async 订阅未填充。

有什么想法吗?

【问题讨论】:

    标签: angular typescript primeng


    【解决方案1】:

    我怀疑您的问题是您调用服务的方式。 AplicacionsSubcomponentService(这可能有错别字,必须是ApplicationsSubcomponentService)实际上是您的组件的一部分,应该使用this 引用。试试这样:

    public scopes$: Observable<Array<ApplicationScope>>;
    
    constructor(private readonly service: AplicacionsSubcomponentService) {
        this.scopes$ = this.service.getScopes().pipe(take(1));
    }
    

    此外,如果您想使用自定义标签(PrimeNG 默认查找名为 label 的属性),您需要在模板中提供它的名称:

    <p-multiSelect name="ambits" [options]="scopes$ | async" optionLabel="name">
    </p-multiSelect>
    

    这是一个有效的Stackblitz 示例。请记住,我使用了虚假服务。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-03
      • 2013-08-03
      • 2014-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多