【发布时间】:2019-07-07 11:29:08
【问题描述】:
当我使用 id 为根元素(应用程序组件)定义选择器时,我对选择器感到困惑,如下所示,我能够渲染组件
index.html
<body>
<div id="root"></div>
</body>
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: '#root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'helloworld';
}
app.component.html
div class='my-text' >My Root Component</div>
<div id='child'></div>
我可以渲染父组件,但是如果我遵循在子选择器中定义的相同规则,我将无法渲染子组件
@Component({
selector: '#child',
templateUrl: './child1.component.html',
styleUrls: ['./child1.component.scss']
})
但是如果我将选择器更改为
selector=[id=child]
为什么选择器定义适用于父项在子项中失败?
Angular 8 版
【问题讨论】:
-
文档:angular.io/api/core/Directive#selector 不要谈论#selector
标签: javascript angular typescript angular8