angular - 为什么不是没有body标签的已知元素
问题描述
我是这个角度 6 的新手。这可能很愚蠢,但我想明确我的概念。下面是 appComponent typescript 的代码 my
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 {
}
当我<app-root>
以以下格式输入 index.html 时。它工作得很好。
<html>
<body>
<app-root></app-root>
</body>
</html>
但是当我删除 html 和 body 标签时,它只会给我一个下面给出的错误。
main.ts:12 Error: 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
所以我的问题是..我必须总是<app-root>
用html或body标签写吗?或者有没有其他方法可以 <app-root>
在不写html或body标签的情况下写?
谢谢
解决方案
推荐阅读
- laravel - Laravel Eloquent - 获取特定行和其他
- python - 获取集合的元素,不包括一些
- vue.js - Mixin 渲染函数组合
- facebook - 检测 Facebook API 用户货币的新方法
- ionic3 - 我的通用链接不起作用,但深层链接有效
- java - 无法将对象放入连接到其他对象的哈希图中
- azure-ad-graph-api - Graph API - 获取特定时间间隔内的可用房间列表
- matlab - 如何构建一个 Matlab 工具箱
- angular - 在 Laravel 中导入 Excel 工作表并在 UI 中显示提取的数据
- ruby-on-rails - 我是否需要在 has_and_belongs_to_many 关系中为模型显式添加外键?