当我尝试从API获取JSON并打印其中的数据时,出现了以下错误。虽然可以正确打印数据,但此错误会在控制台上显示,我不知道如何修复。
HTML
Obs: HTML会输出"bla bla bla"。
{{datas[0].dimension}}
TS
datas: Data[];
this.abcService.getDatas().subscribe(datas => {
this.datas = datas;
console.log(datas);
});
从API获取的JSON(console.log)
(1) [{…}]
0:
dimension:"bla bla bla"
__proto__:Object
length:1
控制台完整错误信息
ERROR TypeError: Cannot read property '0' of undefined
at Object.eval [as updateRenderer] (GraphicsComponent.html:11)
at Object.debugUpdateRenderer [as updateRenderer] (core.es5.js:13113)
at checkAndUpdateView (core.es5.js:12260)
at callViewAction (core.es5.js:12620)
at execComponentViewsAction (core.es5.js:12552)
at checkAndUpdateView (core.es5.js:12261)
at callViewAction (core.es5.js:12620)
at execEmbeddedViewsAction (core.es5.js:12578)
at checkAndUpdateView (core.es5.js:12256)
at callViewAction (core.es5.js:12620)
DebugContext_ {view: {…}, nodeIndex: 17, nodeDef: {…}, elDef: {…}, elView: {…}}
component: (...)
componentRenderElement:(...)
context:(...)
elDef:{index: 16, parent: null, renderParent: null, bindingIndex: 0, outputIndex: 0, …}
elOrCompView:(...)
elView:{def: {…}, parent: {…}, viewContainerParent: null, parentNodeDef: {…}, context: GraphicsComponent, …}
injector:(...)
nodeDef:{index: 17, parent: {…}, renderParent: {…}, bindingIndex: 0, outputIndex: 0, …}
nodeIndex:17
providerTokens:(...)
references:(...)
renderNode:(...)
view:{def: {…}, parent: {…}, viewContainerParent: null, parentNodeDef: {…}, context: GraphicsComponent, …}
__proto__:Object
Obs: HTML会输出"bla bla bla"。