小编Raj*_*471的帖子

在路由器中使用组件时,选择器没有匹配任何元素

我不太习惯 Angular 2 路由器。我写了一个 HomeComponent,它对我来说很好用。现在,当我在路由器中使用它时,它会按组件名称(而不是选择器)显示在 中。因此,我的页面输出通过不使用在其装饰器中定义的选择器而具有 Homecomponent。

现在我收到一个警告,说选择器“main-home”不匹配任何元素。

请建议我如何消除此错误。我应该更改我的页面组件结构吗?

app.module.ts

import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'about-us', component: LoginComponent}
Run Code Online (Sandbox Code Playgroud)

应用程序组件.html

<app-header></app-header>
<main>
  <router-outlet></router-outlet>
</main>
Run Code Online (Sandbox Code Playgroud)

home.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'main-home',
  templateUrl: './home.compoment.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent {}
Run Code Online (Sandbox Code Playgroud)

错误/警告

EXCEPTION: Error in :0:0 caused by: The selector "main-home" did not match any elements
ErrorHandler.handleError
ORIGINAL EXCEPTION: The selector "main-home" did not …
Run Code Online (Sandbox Code Playgroud)

webpack angular

1
推荐指数
1
解决办法
4574
查看次数

标签 统计

angular ×1

webpack ×1