Max*_*x K 4 import typescript angular
如何将角度6中的相对导入转换为绝对导入?
例如
使environments/environment代替
../../../../environments/environment
Run Code Online (Sandbox Code Playgroud)
th3*_*guy 11
这实际上是针对TypeScript的,不一定是Angular.以下是您需要tsconfig.json在项目根目录中添加到文件中的示例:
{
// Other TS options here
"compilerOptions": {
// more stuff is usually here
"paths": {
"@constants/*": ["./app/constants/*"],
"@components/*": ["./app/components/*"],
"@directives/*": ["./app/directives/*"],
"@env/*": ["./environments/*"],
"@models/*": ["./app/models/*"],
"@services/*": ["./app/services/*"],
"@states/*": ["./app/state-management/*"]
}
},
// ...other stuff can be here too
}Run Code Online (Sandbox Code Playgroud)
然后,您将能够在特定的文件/组件中执行此操作:
import { LoggerService } from '@services/logger/logger.service';Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1596 次 |
| 最近记录: |