내 프로젝트에는 다음과 같은 구조가 있습니다.
src
- component-a
-- component-a.component.ts
-- component-a.html
-- component-a.scss
-- component-a.component.spec.ts
- component-b
-- component-b.component.ts
-- component-b.html
-- component-b.scss
-- component-b.component.spec.ts
- app.component.ts
- app.module.ts
- app.html
내 app.component.ts 내에서 component-a를 사용 하고 있으므로 app.module.ts의 선언에 포함했습니다.
declarations: [
App, ComponentA,
],
그리고 app.html에서 : <component-a></component-a>
지금은 추가 할 구성 요소-B를 내 내부 구성 요소-A . 그래서 내가 시도한 것이 무엇이든 component-a.html<component-b></component-b>
내부를 사용할 때이 오류가 발생합니다.
Unhandled Promise rejection: Template parse errors:
'component-b' is not a known element:
1. If 'component-b' is an Angular component, then verify that it is part of this module.
2. If 'component-b' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
[ERROR ->]<component-b></component-b>
"): ng:///AppModule/ComponentA.html@7:6 ; Zone: <root> ; Task: Promise.then ; Value:
component-a.html에서 component-b를 어떻게 사용합니까?
코멘트 섹션에서 논의했듯이. ComponentB
내부에 제공 app.module
하여 앱 전체에서 가져올 수 있습니다.
import {NgModule} from '@angular/core';
@NgModule({
...
declarations: [
AComponent, BComponent
]
})
export class AppModule {}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다