gpt4 book ai didi

angular - 避免工作区中 Angular 项目的相对路径

转载 作者:行者123 更新时间:2023-12-02 12:17:50 27 4
gpt4 key购买 nike

首先,我应该说我已经使用以下命令创建了 Angular 工作区:

ng new angular-apps --create-application=false

工作区根目录中的 tsconfig.json :

{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}

然后使用以下命令在此工作区中创建一个项目:

ng generate application cac-web

这是位于 cac-web 应用程序根目录中的 tsconfig.app.json:

{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/app",
"types": [],
"moduleResolution":"classic",
"baseUrl": "src",
"paths": {
"@app/*": [
"app/*"
],
"@app/core/*": [
"app/core/*"
],
"@app/shared/*": [
"app/shared/*"
],
"@env/*": [
"environments/*"
]
}
},
"files": [
"src/main.ts",
"src/polyfills.ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"src/test.ts",
"src/**/*.spec.ts"
]
}

在 cac-web 应用程序中,我创建了共享模块,然后(models 文件夹/student.model.ts)当我想在另一个模块中使用这个模型时,出现以下错误?

enter image description here

找不到模块“@app/shared/models/student.model”

编辑:

这是我的项目的结构:

|node_modules
|projects--------------cac-web|e2e-----------------|src
| | |protractor.conf.js
| | |tsconfig.json
| |src-----------------|app-----------------|client(Module)-----------------|client-list(component)
| | | |shared(Module)-----------------|models(student.model.ts)
| | | | |shared.module.ts
| | | |app-routing.module.ts
| | | |app.component.html
| | | |app.component.ts
| | | |app.module.ts
| | |assets
| | |environments
| | |index.html
| | |main.ts
| | |polyfills.ts
| | |styles.css
| | |test.ts
| |browserslist
| |karma.conf.js
| |tsconfig.app.json
| |tsconfig.spec.json
| |tslint.json
|.editorconfig
|.gitignore
|angular.json
|package-lock.json
|package.json
|README.md
|tsconfig.json
|tslint.json

最佳答案

请勿更改 tsconfig.app.json 文件。

按照每个新项目的方式修改您的主tsconfig.json:

{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@app/*": [
"projects/cac-web/src/app/*"
],
"@app/core/*": [
"projects/cac-web/src/app/core/*"
],
"@app/shared/*": [
"projects/cac-web/src/app/shared/*"
],
"@env/*": [
"projects/cac-web/src/environments/*"
]
}
}
}

关于angular - 避免工作区中 Angular 项目的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57508639/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com