选择器“app-root”与任何元素都不匹配 || 角6

zai*_*han 1 angular angular5 angular6

我是 Angular 6 的新手,正在为教师开发管理面板。我开发了整个管理面板,没有任何问题。开发管理客户端后给了我一个单独的 html 文件用于登录目的。这就是整个问题的开始。所以我决定通过路由来完成。我创建了管理面板和登录页面的布局。但现在我收到 **“app-root”选择器不匹配** 错误。

下面是我的 appComponent 打字稿

import { Component, OnInit, Inject } from '@angular/core';
import {ToastrService} from './services/toastr.service';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: [],
  providers:[ToastrService]
})
export class AppComponent  {
  }
Run Code Online (Sandbox Code Playgroud)

这是我的index.html

<app-root>loading....</app-root>
Run Code Online (Sandbox Code Playgroud)

以下是我收到的错误

the selector "app-root" did not match any elements
at DefaultDomRenderer2.push../node_modules/@angular/platform-browser/fesm5/platform-browser.js.DefaultDomRenderer2.selectRootElement (platform-browser.js:1073)
at BaseAnimationRenderer.push../node_modules/@angular/platform-browser/fesm5/animations.js.BaseAnimationRenderer.selectRootElement (animations.js:229)
at DebugRenderer2.push../node_modules/@angular/core/fesm5/core.js.DebugRenderer2.selectRootElement (core.js:20837)
at createElement (core.js:17499)
at createViewNodes (core.js:19737)
at createRootView (core.js:19690)
at callWithDebugContext (core.js:20722)
at Object.debugCreateRootView [as createRootView] (core.js:20208)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:18029)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create (core.js:7812)
Run Code Online (Sandbox Code Playgroud)

我缺少什么。请任何人帮忙。

小智 5

我可以通过将 body 标记添加到包含 app-root 标记的 index.html 来解决类似的问题,如下所示:

<body>
<app-root></app-root>
</body>
Run Code Online (Sandbox Code Playgroud)