2017-01-24 21 views
1

聲明隨着angular2應用程序,我已經安裝了tslint延長我的VS代碼之後出現,公共實例成員函數的聲明不允許私有實例成員函數

的應用程序工作正常,但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 : '' 
    }; 
} 

什麼是修復?

+0

在整個代碼或特定代碼行中是否顯示下劃線? – Habeeb

+0

它顯示的配置文件對象 – Sajeetharan

+0

配置文件:對象= {0}配置文件:'http://www.appresume.com/cv_templates/cv_2_1/conf/images/profile.jpg', 姓氏:'約翰', 姓氏:'Doe', detailUrl:'' }; – Sajeetharan

回答

5

這是很好的做法,範圍的方法和變量爲public,protected或private。 TsLint對你如何訂購通常按照這個順序有意見。

移動。因此你的構造上面你的對象將其定義爲私有的(我想這是因爲你必須回到它的方法),並定義getProfile()作爲公衆假期,你的構造下。 TsLint似乎並不關心構造函數,所以不需要一個,但如果你想要的話可​​以有一個。

希望有所幫助。