Angular Typescript-导入后导出的变量(字典)未定义

Angular Typescript-导入后导出的变量(字典)未定义,angular,typescript,Angular,Typescript,在.ts文件中,我定义了一个字典,如下所示: export var substatuses = { 'not_actuated': { name: 'Not actuated', color: '#F52323', iconColor: 'color-red' }, 'executing_procedure': { name: 'Executing procedure', color: '#F

在.ts文件中,我定义了一个字典,如下所示:

export var substatuses = {
    'not_actuated': {
        name: 'Not actuated',
        color: '#F52323',
        iconColor: 'color-red'
    },
    'executing_procedure': {
        name: 'Executing procedure',
        color: '#F78521',
        iconColor: 'color-orange'
    },
    'procedure_executed': {
        name: 'Procedure executed',
        color: '#F2C618',
        iconColor: 'color-yellow'
    },
    'unknown': {
        name: 'Unknown',
        color: '#767676',
        iconColor: 'color-gray'
    },
    'can_not_act': {
        name: 'Can not act',
        color: '#0082F0',
        iconColor: 'color-blue'
    },
    'ok': {
        name: 'Ok',
        color: '#36B07F',
        iconColor: 'color-green'
    },
};
然后在一个角度分量上,我通过以下方式导入它:

import { substatuses } from 'src/app/core/dictionaries/substatuses';
并尝试将其用作普通词典:

substatuses['ok']
但我得到一个“ERROR-TypeError:无法读取未定义的属性'ok'


为什么我的变量没有在我的组件之前初始化?

使用
var
声明的变量被提升(),这意味着它们定义的时间和设置的值可能与代码中的内容不匹配


现在最好的方法就是根本不使用
var
。使用ES6
const
let
声明所有变量,它们将不再被提升,因此更容易理解

var
是第一个变为
const
的候选者,如果您实际询问为什么
子状态['ok']
会触发错误,因为所有附加的
this.geoMarkers.features[i].properties.elements[ii].scenarios[iii].substatus
只是混淆,实际上,您应该测试它是否确实是错误源。如果它是AAAAA,则解决了问题。不知道为什么。嗯,这个错误在
这个.geoMarkers.features[i].properties.elements[ii].scenarios[iii].substatus中的某些地方,你需要进一步调试它。使用字符串以一种丑陋的方式访问对象不会使它们成为C风格的字典。只是说…@Deniscandio,这正是我的观点。它们是物体,假装不是是毫无意义的。