2016-11-03 20 views
0

我想在我的課堂裏使用const maxOverviewTextLength:number = 20;。但是我的ide vscode給出錯誤A class member cannot have the const keyword如何在類中使用const關鍵字Typescirpt/angular2

如何在類內使用const。 Plz幫助。

export class HomeComponent implements AfterViewInit{ 

movieName:string = ""; 

movieSearchActive:boolean = true; 

popularMovieData:Array<any> = []; 

const maxOverviewTextLength:number = 20; 

constructor(private _movieListService:MovielistsService){ 

} 
} 
+0

你可以嘗試聲明爲私有,如果你要使用它裏面唯一的類? –

+0

[public static const in typingcript]可能的重複(http://stackoverflow.com/questions/22991968/public-static-const-in-typescript) – Fiddles

+1

也許問題是一個類成員不能有'const'關鍵字。 –

回答