【发布时间】:2020-07-13 16:35:14
【问题描述】:
当我尝试以角度输出我的帖子时出现错误。请帮忙解决这个问题...
错误信息
解析模板时出错:意外的结束标记“app-post-list”。
我的 post-list.component.ts 代码
import { Component } from "@angular/core";
@Component({
selector: 'aap-post-list',
templateUrl: './post-list.component.html'
})
export class PostListComponent {}
我的 post-list.component.html
<mat-accordion>
<mat-expansion-panel>
<mat-expansion-panel-header>
The expansion title!
</mat-expansion-panel-header>
<p>I'm in an expansion panel!</p>
</mat-expansion-panel>
</mat-accordion>
app.component.html 代码
<app-header></app-header>
<main>
<app-post-create></app-post-create>
<aap-post-list></app-post-list>
</main>
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { MatInputModule} from '@angular/material/input';
import { MatCardModule} from '@angular/material/card';
import { MatButtonModule } from '@angular/material/button';
import { MatToolbarModule } from '@angular/material/toolbar';
import { MatExpansionModule } from '@angular/material/expansion';
import { AppComponent } from './app.component';
import {PostCreateComponent} from './posts/post-create/post-create.component';
import { HeaderComponent } from './header/header.component';
import { PostListComponent } from './posts/post-list/post-list.component';
import { from } from 'rxjs';
@NgModule({
declarations: [
AppComponent,
PostCreateComponent,
HeaderComponent,
PostListComponent
],
imports: [
BrowserModule,
FormsModule,
BrowserAnimationsModule,
MatInputModule,
MatCardModule,
MatButtonModule,
MatToolbarModule,
MatExpansionModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.spec.ts
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { PostListComponent } from './posts/post-list/post-list.component';
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent,
PostListComponent
],
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'mean-learning'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('mean-learning');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('mean-learning app is running!');
});
});
请让我知道我错在哪里以及如何解决这个问题。
【问题讨论】:
-
这是一个错字。在 app.component.html 中,将
<aap-post-list></app-post-list>替换为<aap-post-list></aap-post-list>。更好的是,将组件选择器更改为app-post-list。 -
如果问题解决请点击答案上的已解决图标
-
现在我收到此错误消息 src/app/app.component.html:4:5 - error NG8001: 'app-post-list' is not a known element: If 'app-post- list' 是一个 Angular 组件,然后验证它是这个模块的一部分。如果“app-post-list”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“@NgModule.schemas”以禁止显示此消息。
src/app/app.component.ts:5:16 templateUrl: './app.component.html', 组件AppComponent的模板出错。