数据库为空时无法读取未定义的属性“替换”

时间:2019-05-25 11:16:40

标签: angular typescript angular6

我使用以下代码从数据库中以Angular显示XML数据:

{{apiattempt?.raw_request | xmlBeautyfier }}

但是当DB中的数据为Null时,我得到了错误:

TypeError: Cannot read property 'replace' of undefined
    at vkbeautify.push../node_modules/vkbeautify/index.js.vkbeautify.xml (index.js:83)
    at XmlBeautyfierPipe.push../src/app/shared/pipes/xml-beautyfier.pipe.ts.XmlBeautyfierPipe.transform (xml-beautyfier.pipe.ts:9)
    at checkAndUpdatePureExpressionInline (core.js:9939)
    at checkAndUpdateNodeInline (core.js:10511)
    at checkAndUpdateNode (core.js:10469)
    at debugCheckAndUpdateNode (core.js:11102)
    at debugCheckRenderNodeFn (core.js:11088)
    at Object.eval [as updateRenderer] (ApiAttemptDetailsComponent.html:33)
    at Object.debugUpdateRenderer [as updateRenderer] (core.js:11080)
    at checkAndUpdateView (core.js:10456)

您知道我该如何预防?我可以只打印空行吗?

0 个答案:

没有答案