【发布时间】:2016-11-18 13:16:07
【问题描述】:
我是 angular 2 的新手,在多个组件中,我在一个文件夹文件中编写了两个组件,我在第一个文件中导入了第二个类并给出了指令:类,但它显示错误! 这里是 app.module.ts 文件
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
这里是第一个组件文件app.component.ts
import { Component } from '@angular/core';
import { mydetailsComponent } from './app.details';
@Component({
selector: 'my-app',
template: `<h1>Welcome to this Application...</h1>
<p>We have the App details here:</p>
<mydetails></mydetails>
`
directives: [ mydetailsComponent ] })
export class myAppComponent { }
这里是第二个组件文件app.details.ts
import { Component } from '@angular/core';
@Component({
selector: 'mydetails',
template: `<ul>
<li>Settings</li>
<li>Profile</li>
<li>Games</li>
<li>Gallery</li>
`
})
export class mydetailsComponent { }
请告诉我们如何使用和显示多个组件!
【问题讨论】: