![](/img/trans.png)
[英]What is the meaning of this error “Declaration of instance field not allowed after declaration of instance method.”
[英]Declaration of public instance member function not allowed to appear after declaration of private instance member function
使用angular2 app我已經為我的vs代碼安裝了tslint擴展,
該應用程序工作正常,但tslint顯示要糾正的行,
import { Injectable } from '@angular/core';
@Injectable()
export class UserProfileService{
constructor() {
}
getProfile() {
return this.profile;
}
profile: Object = {
profilePic: 'http://www.appresume.com/cv_templates/cv_2_1/conf/images/profile.jpg',
firstName: 'John',
lastName:'Doe',
detailUrl : ''
};
}
什么是修復?
將您的方法和變量作為公共,受保護或私有的范圍進行定位是一種很好的做法。 TsLint對你如何按照這個順序訂購它們有一個意見。
因此,將您的對象移到構造函數上方,將其定義為private(我假設它是一個返回它的方法)並將getProfile()定義為構造函數下的公共假。 TsLint似乎並不關心構造函數,所以不需要一個,但如果你想要它可以有一個。
希望有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.