2
我有一些组件(例如评论)添加到我的应用程序: 我想:单独的组件添加到角2
在comment.component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'am-comments',
template: `<h4>{{title}}</h4>`
})
export class CommentComponent {
title = 'Comments title';
}
我的应用程序.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { CommentComponent } from './comment.component'; <--
@NgModule({
imports: [
BrowserModule,
FormsModule
],
declarations: [
AppComponent,
CommentComponent // <--
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
最后在输出:
<am-comments>Waiting...</am-comments>
但它不从CommentComponent outsite父组件输出模板
我错过了什么?
风向结构很简单:
您需要将包含'CommentComponent'的模块导入到您使用它的模块中。在'AppModule'或其他模块中,'正在等待...... am-comments>吗? –
我需要创建单独的组件,但使用这种方法我只能创建子组件。 例如在父母组件模板中:template:'
somehtml
对不起,我不理解您的评论。你可以尝试重新措辞吗? “只能创建子组件”的意思是什么,你是什么意思,“不从父组件外的CommentComponent输出模板”? –