InvalidPipeArgument:''表示管道'AsyncPipe'在invalidPipeArgumentError

缺口

我试图使用管道和映射从Observable提取字符串值,但最终我总是得到一个空字符串。我希望有人可以帮助我了解此问题的原因。

我有一个http服务,可从后端获取文件:

getFiles(url: string, idProject: number, docProject: string): Observable<any> { 
return this.http.get(`${this.hostUrl}${url}/${idProject}/${docProject}`); 
  }

我这样称呼getFiles(...):

  showFile = false;
  fileUploads: Observable<string[]>;
.
.
.
showFiles(enable: boolean) {
    this.showFile = enable;

    if (enable) {
this.uploadService.getFiles('/projets', this.service.getProjet().idProjet,
  'documentProjets/pv/'//+ td.nomTypeDoc +'/getallfiles')
            .pipe( 
                  map( response => {
                  return response.slice(
                         response.indexOf("files"), 
                         response.lastIndexOf("?"))
                         })).subscribe(
                           (data) => {
                            this.fileUploads=data
                            console.log(data)},
                           (error) => console.log(error));
}
}

Map之前的结果是:

http://localhost:8080/api/v1/pv/files/file1.jpg?projetId=563, http://localhost:8080/api/v1/pv/files/file2.jpg?projetId=563 

MAp之后是:一个空数组。

HTML:

<button class="button btn-info" *ngIf='showFile' (click)='showFiles(false)'>Hide Files</button>

<button class="button btn-info" *ngIf='!showFile' (click)='showFiles(true)'>Show Files</button> 


<div [hidden]="!showFile">
  <div class="panel panel-primary">
    <div class="panel-heading">Liste des fichiers</div>

    <div *ngFor="let file of fileUploads | async">  
      <div class="panel-body">
        <app-details-upload [fileUpload]='file'></app-details-upload>
      </div>
    </div>
  </div>
</div>

我不知道为什么我得到一个空值'',这是我的consol错误:

ListUploadComponent.html:3错误错误:InvalidPipeArgument:''在AsyncPipe.push ../ node_modules/@angular/common/fesm5/common.js.AsyncPipe._selectStrategy(在invalidPipeArgumentError(common.js:3981)处为管道'AsyncPipe' / node_modules / @ angular / common /在AsyncPipe.push ../ node_modules/@angular/common/fesm5/common.js.AsyncPipe._subscribe(common.js:4580)在AsyncPipe.push ../ node_modules / @ angular / common / fesm5 / common.js.AsyncPipe.transform(common.js:4562)在Object.eval [作为updateDirectives](ListUploadComponent.html:10)在Object.debugUpdateDirectives [作为updateDirectives](core.js:11054)在checkAndUpdateView(核心.js:10451)位于callViewAction(core.js:10692),而execComponentViewsAction(core.js:10634)位于checkAndUpdateView(core.js:10457)

先感谢您。

安德鲁·艾伦

异步管道采用Observable,并在模板中为您订阅,并在组件破坏时为您退订。遵守在可观察流变量末尾使用$的约定。

以下

<div *ngFor="let v of values$ | async">
  {{v}}
</div>

相当于

<div *ngFor="let v of values">
  {{v}}
</div>

在ts文件中的何处执行此操作

this.values$.subscribe(values => this.values = values)


在您的示例中,您可以从模板中删除异步管道,也可以删除订阅并分配流。

this.fileUploads$ = this.uploadService.getFiles('/projets', this.service.getProjet().idProjet,
  'documentProjets/pv/'//+ td.nomTypeDoc +'/getallfiles')
            .pipe( map( response => {
                  return response.slice(
                         response.indexOf("files"), 
                         response.lastIndexOf("?"))
                         }))

如果需要console.log进行调试,请使用tap RxJS可管道运算符。


更新-调试步骤后

tap运算符不会影响流(它可用于导航或日志记录之类的副作用),因此它可以告诉您确切的管道流中的下一个运算符正在获取...字符串数组。因此,键入以下内容...

this.fileUploads$ = this.yourService.pipe(
    // tap(console.log),
    map((responseUrls: string[]) => {
        return responseUrls.map((url: string) => {
           // some function that 
           // uses string methods
           // or regex
           // to return what you
           // want e.g.
           return url.slice(
               url.indexOf(‘files’),
               url.indexOf(‘?’)
           )
        })
    })
    // }),
    // tap(console.log)
)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

InvalidPipeArgument: '[object Object]' 用于管道 'AsyncPipe' --> 适用于第一个循环,但不适用于后者

来自分类Dev

在另一个管道中注入 AsyncPipe

来自分类Dev

管道'AsyncPipe'的角度无效参数'z,x,y'

来自分类Dev

错误:InvalidPipeArgument

来自分类Dev

错误:InvalidPipeArgument:“无法将“ 27-08-2020”转换为日期”管道“ DatePipe”

来自分类Dev

PHP InvalidPipeArgument中的角度和日期:'无法将“ [object Object]”转换为日期”,用于管道“ DatePipe”

来自分类Dev

Angular2 n-为管道“ AsyncPipe”获取无效的参数[object Object] ...

来自分类Dev

Angular2:* ngFor,AsyncPipe和index

来自分类Dev

AsyncPipe 无法正常工作,原因不明

来自分类Dev

DatePipe 的 InvalidPipeArgument,默认不支持 IST 时区

来自分类Dev

当函数返回间隔时,AsyncPipe无法正常工作

来自分类Dev

多个下拉菜单的角度AsyncPipe加载一次

来自分类Dev

使用sideEffects时,Angular 10的树摇晃震动了AsyncPipe

来自分类Dev

用knex.js管道表示

来自分类Dev

什么是| (管道)表示TypeScript中类型的开头

来自分类Dev

仅当不共享订阅时,AsyncPipe初始值才为null

来自分类Dev

Angular:在异步调用和AsyncPipe之后创建动态的反应形式

来自分类Dev

如何在Angular / Ionic Observable / Promise中的AsyncPipe中返回默认值

来自分类Dev

如何将分页与Observables和Angular 9中的AsyncPipe结合?

来自分类Dev

如何表示远端机器上的管道和本地机器上的管道

来自分类Dev

用于Web服务参数的管道式文本(以质量表示)

来自分类Dev

有关在GitLab CI管道的图形表示中连接作业的线的问题

来自分类Dev

Coreutils(或其他方式)“ ls”:管道传输时不附加表示类型的符号

来自分类Dev

管道:写入管道的前面

来自分类Dev

管道广播

来自分类Dev

Redis管道

来自分类Dev

Biztalk管道

来自分类Dev

响应管道

来自分类Dev

条件管道

Related 相关文章

  1. 1

    InvalidPipeArgument: '[object Object]' 用于管道 'AsyncPipe' --> 适用于第一个循环,但不适用于后者

  2. 2

    在另一个管道中注入 AsyncPipe

  3. 3

    管道'AsyncPipe'的角度无效参数'z,x,y'

  4. 4

    错误:InvalidPipeArgument

  5. 5

    错误:InvalidPipeArgument:“无法将“ 27-08-2020”转换为日期”管道“ DatePipe”

  6. 6

    PHP InvalidPipeArgument中的角度和日期:'无法将“ [object Object]”转换为日期”,用于管道“ DatePipe”

  7. 7

    Angular2 n-为管道“ AsyncPipe”获取无效的参数[object Object] ...

  8. 8

    Angular2:* ngFor,AsyncPipe和index

  9. 9

    AsyncPipe 无法正常工作,原因不明

  10. 10

    DatePipe 的 InvalidPipeArgument,默认不支持 IST 时区

  11. 11

    当函数返回间隔时,AsyncPipe无法正常工作

  12. 12

    多个下拉菜单的角度AsyncPipe加载一次

  13. 13

    使用sideEffects时,Angular 10的树摇晃震动了AsyncPipe

  14. 14

    用knex.js管道表示

  15. 15

    什么是| (管道)表示TypeScript中类型的开头

  16. 16

    仅当不共享订阅时,AsyncPipe初始值才为null

  17. 17

    Angular:在异步调用和AsyncPipe之后创建动态的反应形式

  18. 18

    如何在Angular / Ionic Observable / Promise中的AsyncPipe中返回默认值

  19. 19

    如何将分页与Observables和Angular 9中的AsyncPipe结合?

  20. 20

    如何表示远端机器上的管道和本地机器上的管道

  21. 21

    用于Web服务参数的管道式文本(以质量表示)

  22. 22

    有关在GitLab CI管道的图形表示中连接作业的线的问题

  23. 23

    Coreutils(或其他方式)“ ls”:管道传输时不附加表示类型的符号

  24. 24

    管道:写入管道的前面

  25. 25

    管道广播

  26. 26

    Redis管道

  27. 27

    Biztalk管道

  28. 28

    响应管道

  29. 29

    条件管道

热门标签

归档