設(shè)置別名
在根目錄下tsconfig.json中添加baseUrl和paths
{ "compilerOptions": { "baseUrl": "src", "paths": { "@app/*": ["app/*"], "@assets/*": ["assets/*"], "@env/*": ["environments/*"], "@views/*": ["app/views/*"], "@core/*": ["app/core/*"], "@constants": ["app/core/constants/*"], "@model/*": ["app/core/model/*"], "@interceptors/*": ["app/core/interceptors/*"], "@services/*": ["app/core/services/*"], "@validators/*": ["app/core/validators/*"], "@shared/*": ["app/shared/*"], "@components/*": ["app/shared/components/*"], "@directives/*": ["app/shared/directives/*"], "@guards/*": ["app/shared/guards/*"], "@pipes/*": ["app/shared/pipes/*"] }, }
訪問環(huán)境變量
import { environment } from '@env/environment'
添加了@env別名,以便能夠import { environment } from '@env/environment',從應(yīng)用程序中的任何位置輕松訪問環(huán)境變量。它適用于所有指定的環(huán)境,因為cli它會根據(jù)--env傳遞給ng build命令的標(biāo)志自動解析正確的環(huán)境文件。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com