Angular 角节点的目录结构
我已经在angular.io上看到了目录结构,但我对他们提供的指南不满意。通常我们有可以在任何模块中使用的服务和模型,请查看以下结构Angular 角节点的目录结构,angular,Angular,我已经在angular.io上看到了目录结构,但我对他们提供的指南不满意。通常我们有可以在任何模块中使用的服务和模型,请查看以下结构 app |---modules | |---account | | |---list-account.component.ts|html|css | | |---add-account.component.ts|html|css | |---customer
app
|---modules
| |---account
| | |---list-account.component.ts|html|css
| | |---add-account.component.ts|html|css
| |---customer
| |---list-customer.component.ts|html|css
| |---add-customer.component.ts|html|css
|---services
| |---account.service.ts
| |---customer.service.ts
|---models
| |---account.model.ts
| |---customer.model.ts
我尝试使用以下结构,但在导入typescript中的文件时,相对URL太不清楚。例如,如果我想在addaccount.component
中导入account.model
,import语句如下所示
// ../../ looks so wierd, is it a good practise?
import { AccountModel } from '../../models/account.model';
// is it good practise to use absolute paths to import for typescript in angular?
import { AccountModel } from '~/models/account.model';
我想在所有组件和服务中重复使用我的模型。请给我推荐一些好的目录结构。非常感谢您的帮助。由shows设计的角度样式指南,鼓励您使用局部方式。因此,您应该使用:
从'../../models/account.model'导入{AccountModel};
资料来源:由设计的角度式导轨,建议使用局部方式。因此,您应该使用:
从'../../models/account.model'导入{AccountModel};
来源:使用桶进行进口。绝对路径参考在您进入生产阶段时总是很好的,与相对路径相比,绝对路径参考减少了工作量用于导入。绝对路径参考总是好的,当您移动到生产时,与相对路径相比,它减少了工作量