简体   繁体   English

我的angular2导入代码有什么问题

[英]what's wrong with my angular2 import code

As code Below, Im new to angular2, why when i use "app/app.module" the light server returns an error: 如下面的代码,我是angular2的新手,为什么当我使用“ app / app.module”时,灯光服务器返回错误:

import {AppModule} from "app/app.module";//wrong
import {AppModule} from "./app.module";  //right

app/main.ts(5,25): error TS2307: Cannot find module '/app/app.module'. app / main.ts(5,25):错误TS2307:找不到模块“ /app/app.module”。

what's the problem?is there any way to use "app/app.module" ? 有什么问题?有没有办法使用"app/app.module"

this is the structure image, exactly flow the angular 2 tut. 这是结构图像,正好流过2个tut。

I think the problem is because of tsconfig.json, from angular 2 tut. 我认为问题是由于tsconfig.json从角度2 tut。 but I dont know how to fix it. 但我不知道如何解决。

thanks everybody 谢谢大家

The both of your example are using a relative path 您的两个示例都使用相对路径

The path of the AppModule is relative to your current file. AppModule的路径是相对于您当前文件的。

If you using Webpack or SystemJS to import, you should follow this constraint 如果使用Webpack或SystemJS导入,则应遵循此约束

AppModule _> same folder

./AppModule -> inside a file

../AppModule -> go out from current directory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM