【发布时间】:2019-02-09 02:59:04
【问题描述】:
我在我的 Angular 项目中使用 utils -> Constants.ts 中的以下代码。
Constants.ts
export class Constants {
static readonly LOCAL_STORAGE = 'LOCAL_STORAGE';
static readonly SESSSION_STORAGE = 'SESSSION_STORAGE';
}
我收到错误:重复的标识符只读。 (属性) Constants.readonly :字符串。 当我将光标放在只读上时。
并且 [ts] '=' 预期。 [ts] 找不到任何名称 LOCAL_STORAGE。 当我将光标放在 LOCAL_STORAGE 上时。
所以当我尝试从另一个 ts 文件中的 session_storage 检索一些数据时,例如 let mobileNo = this.db.get(Constants.SESSSION_STORAGE, Constants.MOBILE_NO); 我面临以下问题错误。
“typeOf 常量”类型上不存在属性“SESSION_STORAGE”。
谁能帮我解决这个错误。
【问题讨论】:
-
为什么不使用枚举?这个简单的功能你不需要一个类
-
啊,抱歉,这是 angular 还是 angularjs 代码 sn-p?
-
@bodorgergely。这是 Angular 6 打字稿
标签: angular typescript session-storage