【发布时间】:2019-08-20 18:38:25
【问题描述】:
首先,我应该说我已经使用以下命令创建了我的 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 应用程序中,我创建了共享模块,然后(模型文件夹/student.model.ts) 当我想在另一个模块中使用此模型时,出现以下错误?
找不到模块“@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 中与
shared文件夹相对应的 glob 不包含子目录。你能试试@app/shared/**/*吗?
标签: angular