简体   繁体   中英

How to import module in the current project from different Directory in Angular 2 Typescript

在此处输入图片说明

In The above image angular2-template is my Angular 2 project. I have defined ContactModule in the common-template folder. How can I import ContactModule from common-template into angular2-template ?

You can't import anything outside of /src/...
that is because the angular2 compiler doesn't look for anything higher than the src folder.
You could however copy the ContactModule from the common-template folder into /angular2-template/src/app and move implement it into your component/module of choice.

For example: move /common-module/commonModuleFolder to /angular2-template/src/app/modules/commonModuleFolder

Then you can go into for example AppComponent and import it like this:
import CommonModule from './modules/commonModuleFolder/common.module'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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