angular - 在 Angular 4 应用程序中设置路径别名

标签 angular

有什么方法可以使用 TypeScript 在 Angular 中设置路径别名 因为把路径放在

import { AuthService } from '../../../common/AuthService';
import { ContactService } from '../../../common/ContactService';

记住相对路径 URI 是非常困惑的。 有什么方法可以创建路径别名并在整个应用程序中使用它们,例如 browserify

最佳答案

如果你使用 typescript,处理这个问题的最好方法是将路径配置放在项目的 tsconfig.json 中:

"baseUrl": "src",
"paths": {
  "@app/*": ["app/*"],
  "@env/*": ["environments/*"]
}

请引用以下文章中的第二点https://medium.com/@tomastrajan/6-best-practices-pro-tips-for-angular-cli-better-developer-experience-7b328bc9db81 , 或官方 ts 文档 https://www.typescriptlang.org/docs/handbook/module-resolution.html#base-url

关于angular - 在 Angular 4 应用程序中设置路径别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44217466/

相关文章:

angular - 如何路由到模块作为模块的子级 - Angular 2 RC 5

angular - 如何在 mat-stepper 中传递模板

angular - 如何在 material-angular-select 上创建回调?

javascript - Angular 中不存在 3

javascript - Angular:找不到名称为: 'date' 的控件

javascript - angular - 基于 mat-select 选项的条件元素

Angular 2 与 ngModel 的双向数据绑定(bind)

angular - 带有键入选项的垫选择

angular - 如何在 Angular 2 的 Material 选择框中显示 md 错误?

angular - 使用 Firebase 身份验证使用户 session 过期