2017-07-19 33 views
0

我必須從角1.3.x的一個網站遷移到角4.3.0如何在Angular 2中存儲值?

雖然經歷的代碼,我

該應用程序使用某種價值

angular.module('abc').value('externalProviderConfigSettings', { 
    settingsVersion: "2.0", 
    facebook: { appKey: '', appSecret: '', redirectUrl: '', state: '', permissions: ['email', 'public_profile', 'user_friends', 'publish_actions', 'manage_pages'] }, 
    twitter: { appKey: '', appSecret: '', redirectUrl: '', state: '', permissions: [] }, 
    linkedin: { appKey: '', appSecret: '', redirectUrl: '', state: '', permissions: ['r_basicprofile', 'r_emailaddress', 'w_share', 'rw_company_admin'] }, 
    google: { appKey: '', appSecret: '', state: '', permissions: [] }, 
    pinterest: { redirectUrl: '' } 
}); 

幾個問題如何在Angular 4.3.0中遷移這些價值。 我正在瀏覽文檔,但無法弄清楚。 同樣存在的.config代碼

angular.module('abc').config 

如何處理,在角2? 它是一個很大的應用程序,我想確保我的方法是正確的。

謝謝!

+0

您可以使用服務來處理應用範圍可達狀態:https://angular.io/tutorial/toh-pt4 – wostex

回答

0

我的辦法是導出一個常量,然後導入它不管你想要的,例如:

環境/ environment.ts

export const environment = { 
    production: false, 
    token_auth_config: { 
    apiBase: 'http://localhost:3000', 
    signInRedirect: '/login' 
    } 
}; 

然後在任何其他文件在導入

import {environment} from '../environments/environment'; 

this.authToken.init(environment.token_auth_config); 
相關問題