【问题标题】:About import {**} from @app/* in angular4 project关于在 angular4 项目中从 @app/* 导入 {**}
【发布时间】:2017-09-19 01:17:24
【问题描述】:

我在angular项目中遇到了一个奇怪的现象。

我的项目是从命令行自动生成的(ng new myproject)

在项目中,目录

  • 应用程序
    • 共享
      • 常见
        • app-component-base.ts
      • 课程
        • app-session.service

app-component-base.ts

import { AppSessionService } from '@shared/session/app-session.service';

tsconfig.app.json:

"paths": {
    "@abp/*": [ "../node_modules/abp-ng2-module/src/*" ],
    "@app/*": [ "./app/*" ],
    "@shared/*": [ "./app/shared/*" ],
    "@node_modules/*": [ "../node_modules/*" ]
}

vscode报错(不影响正常运行,但无法导航到该类):

[ts] Cannot find module '@shared/session/app-session.service'.

我有什么配置错误吗? 谢谢!

我知道可以这样,但我想用通用符号:

import { AppSessionService } from '../session/app-session.service';



@angular/cli: 1.4.2
node: 6.10.2
os: win32 x64
@angular/animations: 4.4.2
@angular/common: 4.4.2
@angular/compiler: 4.4.2
@angular/core: 4.4.2
@angular/forms: 4.4.2
@angular/http: 4.4.2
@angular/platform-browser: 4.4.2
@angular/platform-browser-dynamic: 4.4.2
@angular/router: 4.4.2
@angular/cli: 1.4.2
@angular/compiler-cli: 4.4.2
typescript: 2.5.2

【问题讨论】:

  • 你使用什么版本的cli?
  • @angular/cli: 1.4.2 node: 6.10.2 os: win32 x64 @angular/animations: 4.4.2 @angular/common: 4.4.2 @angular/compiler: 4.4.2 @角度/核心:4.4.2 @angular/forms:4.4.2 @angular/http:4.4.2 @angular/platform-b​​rowser:4.4.2 @angular/platform-b​​rowser-dynamic:4.4.2 @angular/router: 4.4.2 @angular/cli: 1.4.2 @angular/compiler-cli: 4.4.2 typescript: 2.5.2
  • ng-cli 没有生成你提到的文件,你从哪里得到的?
  • 谢谢,但你没明白我的意思。我说的是vscode的智能提示

标签: angular tsconfig


【解决方案1】:

我注意到了几件事。一,你的“路径”设置应该放在 tsconfig.json 而不是 tsconfig.app.json 中。其次,我的路径如下所示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    • 2013-08-07
    • 2011-06-06
    • 1970-01-01
    相关资源
    最近更新 更多