解析模板时出错:意外的结束标记 app-post-list
Errors parsing template: Unexpected closing tag app-post-list
当我尝试在 angular 中输出我的 post 时出现错误。请帮助解决这个问题...
错误信息
解析模板时出错:意外的结束标记 "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!');
});
});
请让我知道我哪里错了以及我是如何解决这个问题的。
您好,您在行号 4 中输入了错误,将 <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 {}
现在应该可以正常工作了
当我尝试在 angular 中输出我的 post 时出现错误。请帮助解决这个问题...
错误信息
解析模板时出错:意外的结束标记 "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!');
});
});
请让我知道我哪里错了以及我是如何解决这个问题的。
您好,您在行号 4 中输入了错误,将 <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 {}
现在应该可以正常工作了