Angular 角度2-多个组件不起作用
我学习了angular 2,但我不能做多重组件,例如,我尝试了这个,但它不起作用: app.module.ts:Angular 角度2-多个组件不起作用,angular,Angular,我学习了angular 2,但我不能做多重组件,例如,我尝试了这个,但它不起作用: app.module.ts: import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { TestComponent } from './test
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { TestComponent } from './test.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, TestComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
app.component.ts:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: './app.component.html'
})
export class AppComponent {}
test.component.ts:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'test',
templateUrl: './test.component.html'
})
export class TestComponent {}
app.component.html:
<h1>Hello World!</h1>
<h2>test</h2>
test.component.html:
<h1>Hello World!</h1>
<h2>test</h2>
您必须从应用程序调用测试组件 在Angular 2中,它是通过html标记选择器完成的 如果你加上
在app.component.html中,它应该呈现测试组件。您能告诉我们您在./app.component.html中做了什么吗?如果您在AppComponent html中指定了test,它将起作用。是否希望您的测试组件显示在应用程序组件中?如果是,请添加到app.component.html