[英]No component from another module is displayed
I tried display component with name main , using selector: 'app-main'.我尝试使用名称main显示组件,使用选择器:'app-main'。 Component main is in NavbarModuleModule.
组件 main 在 NavbarModuleModule 中。
In NavbarModuleModule i make export main component.在 NavbarModuleModule 中,我制作了导出主要组件。
I added NavbarModuleModule module to main module with name app.module .我将NavbarModuleModule模块添加到名为app.module 的主模块中。
Using selector I add him to main template but still component is not loaded.使用选择器我将他添加到主模板但仍未加载组件。
navbar-module.module.ts导航栏-module.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MainComponent } from './main/main.component';
@NgModule({
declarations: [MainComponent],
imports: [
CommonModule
],
exports : [MainComponent]
})
export class NavbarModuleModule { }
Main.component.html主组件.html
<p>main works!</p>
main.component.ts main.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-main',
templateUrl: './main.component.html',
styleUrls: ['./main.component.scss']
})
export class MainComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
app.module.ts - main module app.module.ts - 主模块
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { NavbarModuleModule } from './navbar-module/navbar-module.module';
import { HttpClientModule } from "@angular/common/http";
@NgModule({
declarations: [
AppComponent,
HeaderComponent
],
imports: [
BrowserModule,
HttpClientModule,
NavbarModuleModule
],
providers: [],
bootstrap: [AppComponent, HeaderComponent]
})
export class AppModule { }
Can anyone tell me what i'm doing wrong?谁能告诉我我做错了什么? How can I load this component with other module.
如何使用其他模块加载此组件。
you need to add your maincomponent in bootstrap array which is in Appmodule.您需要在 Appmodule 中的 bootstrap 数组中添加您的主要组件。
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { NavbarModuleModule } from './navbar-module/navbar-module.module';
import { HttpClientModule } from "@angular/common/http";
@NgModule({
declarations: [
AppComponent,
HeaderComponent
],
imports: [
BrowserModule,
HttpClientModule,
NavbarModuleModule
],
providers: [],
bootstrap: [AppComponent, HeaderComponent, MainComponent]
})
export class AppModule { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.