Angular 发生客户端或网络错误:无法读取未定义的属性(读取“viewContainerRef”)

发布于 2025-01-10 08:20:26 字数 1541 浏览 4 评论 0原文

我使用以下 forkJoin 仅对可预览的附件进行预览调用。 canPreview 标志表明了这一点。

但是一旦我添加过滤器,它就会抛出以下错误。我没有在此组件中的任何地方使用 viewContaienrRef 。谁能帮助找出我在这里做错了什么?

'A client-side or network error occurred: Cannot read properties of undefined (reading 'viewContainerRef')'
    forkJoin(
            this.question.attachments
            .filter(attachment => attachment.canPreview) //error after adding this line
            .map((attachment) => {
                const { fileName, attachmentId, canPreview } = attachment;
                const attachmentUploadResult: AttachmentUploadResult = {
                    fileName,
                    attachmentId,
                    canPreview
                };
                return this.uploadService.getBlob(attachmentId).pipe(
                        map((blob) => {
                            return {
                                fileName,
                                attachmentId,
                                imageURL: this.sanitizer.bypassSecurityTrustUrl(
                                    URL.createObjectURL(blob)
                                ),
                                canPreview
                            } as AttachmentUploadResult;
                        }),
                        catchError(() =>
                            of(attachmentUploadResult)
                        )
                    );
            })
        )

谢谢

I am using the following forkJoin to make preview call only for attachment that can be previewable. canPreview flag shows that.

But as soon as I add the filter, it is throwing the following error. I am not using viewContaienrRef anywhere in this component. Can anyone help to find what am I doing wrong here?

'A client-side or network error occurred: Cannot read properties of undefined (reading 'viewContainerRef')'
    forkJoin(
            this.question.attachments
            .filter(attachment => attachment.canPreview) //error after adding this line
            .map((attachment) => {
                const { fileName, attachmentId, canPreview } = attachment;
                const attachmentUploadResult: AttachmentUploadResult = {
                    fileName,
                    attachmentId,
                    canPreview
                };
                return this.uploadService.getBlob(attachmentId).pipe(
                        map((blob) => {
                            return {
                                fileName,
                                attachmentId,
                                imageURL: this.sanitizer.bypassSecurityTrustUrl(
                                    URL.createObjectURL(blob)
                                ),
                                canPreview
                            } as AttachmentUploadResult;
                        }),
                        catchError(() =>
                            of(attachmentUploadResult)
                        )
                    );
            })
        )

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文