选择器“app-root"没有匹配任何元素 ||角 6 [英] The selector "app-root" did not match any elements || angular 6

查看:31
本文介绍了选择器“app-root"没有匹配任何元素 ||角 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to angular 6 and developing admin panel for teachers. i developed the whole admin panel without any problem. After developing admin client gave me a separate html file for login purpose. that's where the whole problem started. So i decided to do it by routing. I created layout for admin panel as well as the login page. But now i am getting ** "app-root" selector did not match** error.

下面是我的 appComponent 打字稿

Below is my appComponent typescript

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  {
  }

这是我的 index.html

This is my index.html

<app-root>loading....</app-root>

下面是我得到的错误

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)

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

What i am missing. Any one please help.

推荐答案

通过向 index.html 添加一个包含 app-root 标记的 body 标记,我能够解决类似的问题,如下所示:

I was able to solve a similar problem by adding a body tag to my index.html that encloses the app-root tag as follows:

<body>
<app-root></app-root>
</body>

这篇关于选择器“app-root"没有匹配任何元素 ||角 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆