Angular 2 中的 const 和 Typescript

Posted

技术标签:

【中文标题】Angular 2 中的 const 和 Typescript【英文标题】:const on Angular2 with Typescript 【发布时间】:2017-01-22 16:38:36 【问题描述】:

为什么在尝试声明 const 时出现错误:

Expecting new line or semicolon

export class MyClass

    const ALLOC_INVESTORS = "Allocation Investors";


【问题讨论】:

如果你 try it on the Playground 它会告诉你 const 不能在类声明中使用。 @MikeMcCaughan typescript 类中 const 的替代方案是什么? ***.com/q/37265275/215552 :) 【参考方案1】:

以防万一。 使用只读而不是 const。

readonly ALLOC_INVESTORS:string = "Allocation Investors";

【讨论】:

以上是关于Angular 2 中的 const 和 Typescript的主要内容,如果未能解决你的问题,请参考以下文章