尝试以角度输出帖子时出现错误。请帮助解决此问题...
错误消息
错误分析模板:意外的结束标记“ 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!');
});
});
请让我知道我在哪里错了以及如何解决此问题。
答案 0 :(得分:0)
您好,您已经在行号 4 中完成了Typo,将<aap-post-list>
更改为<app-post-list>
问题已解决。
app.component.html 代码
<app-header></app-header>
<main>
<app-post-create></app-post-create>
<aap-post-list></app-post-list>
</main>
已更新
您已经更改了<aap-post-list> to <app-post-list>
,所以现在返回
post-list.component.ts
现在将选择器更改为
从“ @ angular / core”导入{组件};
@Component({
selector: 'aap-post-list',
templateUrl: './post-list.component.html'
})
export class PostListComponent {}
到
从“ @ angular / core”导入{组件};
@Component({
selector: 'app-post-list',
templateUrl: './post-list.component.html'
})
export class PostListComponent {}
现在应该可以正常工作