索引页面如何知道要加载哪个app标记

问题描述 投票:-2回答:1

对于index.html页面,我有一个标签,在我的app.component.ts中,选择器是“app”。在我的component.ts中,选择器也是“app”。 angular 7如何知道选择哪个html页面以及选择哪个应用程序,因为它们的名称相同。

app.component.ts:

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

@Component({
  selector: 'app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'example';
}


component.ts:
  import { ApplicationRef, Component } from "@angular/core";

@Component({
    selector: "app",
    templateUrl: "template.html",
    styles: ["/deep/ div { border: 2px black solid;  font-style:italic }"]
})
export class ProductComponent {

}
angular
1个回答
1
投票

Angular不知道。如果使用相同的选择器声明两个不同的组件,并且尝试在同一个模块中使用它们,则会出现错误。您可能不会立即注意到错误,因为两个冲突的组件需要在同一模块中用于Angular才能开始抛出错误。

© www.soinside.com 2019 - 2024. All rights reserved.