有没有办法用TypeScript在Angular中设置路径别名,因为放置路径就好了
import { AuthService } from '../../../common/AuthService';
import { ContactService } from '../../../common/ContactService';
Run Code Online (Sandbox Code Playgroud)
记住相对路径URI是非常混乱的.有没有办法创建路径别名并在整个应用程序中使用它们,比如browserify?
小智 10
如果使用typescript,处理此问题的最佳方法是将路径配置放在项目的tsconfig.json中:
"baseUrl": "src",
"paths": {
"@app/*": ["app/*"],
"@env/*": ["environments/*"]
}
Run Code Online (Sandbox Code Playgroud)
请参阅以下文章https://medium.com/@tomastrajan/6-best-practices-pro-tips-for-angular-cli-better-developer-experience-7b328bc9db81或官方ts docs https中的第二点: //www.typescriptlang.org/docs/handbook/module-resolution.html#base-url
| 归档时间: |
|
| 查看次数: |
4239 次 |
| 最近记录: |