Angular2-cli을 사용하여 두 개의 응용 프로그램 (MyFirstApp
& MySecondApp
)을 만듭니다. 나는 MySecondApp
을 MyFirstApp
으로 가져와 지시문/서비스/구성 요소를 재사용 할 수 있습니다. MyFirstApp
을 가져 오면 다음 컴파일 오류가 발생합니다. Cannot find module 'MyFirstApp'
.Angular2 : 각형으로 작성된 Apps 간의 종속성
$ npm -v
3.9.3
$ node -v
v6.2.1
$ npm list | grep 'angular'
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├── @angular/[email protected]
├─┬ [email protected]
$ ng new MyFirstApp
$ cd MyFirstApp
$ ng g service MyFirstAppService
$ ng build
$ cd ..
$ ng new MySecondApp
$ cd MySecondApp
$ npm install ../MyFirstApp --save #Also tried w/ ng install ../MyFirstApp and github link
$ vim src/app/my-second-app.component.ts
수정 src/app/my-second-app.component.ts
은 그래서 다음과 같습니다 :
import { Component } from '@angular/core';
import { MyFirstAppService } from 'MyFirstApp';
@Component({
moduleId: module.id,
selector: 'MySecondApp',
templateUrl: 'mysecondapp.component.html',
styleUrls: ['mysecondapp.component.css']
})
export class MySecondAppAppComponent {
title = 'MySecondApp works!';
}
내가 import { MyFirstAppService } from 'MyFirstApp';
(즉 import { MyFirstAppServiceService } from './../../node_modules/my-first-app/src/app/my-first-app-service.service';
& 공)의 많은 버전을 시도하고 연주
여기 를 재현하는 방법 system-config.ts
(this 및 this) 행운없이. 나는 항상 Cannot find module 'MyFirstApp'
을 가지고있다.
제안 사항?
편집 : 로 system-config.ts
(선 14-1)을 조정하여 다음 : 나는 import { MyFirstAppServiceService } from 'my-first-app/src/app/my-first-app-service.service';
을 할 수
const map: any = {
'my-first-app': 'vendor/my-first-app/app/index.js'
};
/** User packages configuration. */
const packages: any = {
'my-first-app': {
format: 'cjs'
}
};
. .../dist/...
이 작동하지 않습니다. 오른쪽 할 수있는 방법이 아닌 것 같습니다 ... 가능하지 않아야합니까 import { MyFirstAppServiceService } from 'my-first-app/my-first-app-service.service'
? 결과 vendors/my-first-app/
디렉토리 MyFirstApp
$ # While in MySecondApp
$ tree dist/vendor/my-first-app
dist/vendor/my-first-app
├── angular-cli-build.js
└── config
├── environment.js
├── karma.conf.js
├── karma-test-shim.js
└── protractor.conf.js
감사의 코드가 포함되어 있지 않습니다
참고. 당신의 SRC/응용 프로그램/mysecondapp.component.ts에서
Nop는. '모듈을 찾을 수 없습니다. '/ app/MyFirstApp'.' –