代码之家  ›  专栏  ›  技术社区  ›  JacobIRR

在角度项目中放置类型/类的位置

  •  0
  • JacobIRR  · 技术社区  · 7 年前

    我的项目结构如下:

    e2e
    src
      app
      assets
      modules
        core
        shared
        features
          one
          two 
          three
            components
              ...
            constants
              ...
            services
              ...
            three-routing.module.ts
            three.module.ts
    

    one two three 所有的类都有相同的内部结构,但是我想知道应该把一些类放在哪里来表示。 Three ThreeRetrievalError . 目前,我正在使用一个对象

    1 回复  |  直到 7 年前
        1
  •  3
  •   SiddAjmera    7 年前

    Angular Style Guide 建议创建用于声明类型/数据模型的接口。

    考虑使用 interface

    另外,请考虑在命名这些接口时不要在其名称前面加前缀 I 因为它与TypeScripts命名约定冲突。

    接口 没有一个 前缀 .

    不过,关于它们应该放在哪里,并没有任何既定的指导方针。这完全取决于你喜欢你的文件和文件夹结构。

    也就是说,我通常更喜欢把它们放在自己的文件夹里。所以我猜,在文件夹里 three ,您可以创建 model 将包含 three.model.ts three-retrieval-error.model.ts 接口文件。这些文件的命名源自 this rule from the Angular Style Guide

    feature.type.ts .

    推荐文章