Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 是否正在激活我没有为其写入标记的组件?_Angular_Router Outlet - Fatal编程技术网

Angular 是否正在激活我没有为其写入标记的组件?

Angular 是否正在激活我没有为其写入标记的组件?,angular,router-outlet,Angular,Router Outlet,我目前正在阅读Angular getting started文档中的代码: 我在app.component.html中看到顶栏.component是如何呈现的,因为它说: 路由器出口将在任何时候启动新组件时发出激活事件 正在实例化,并且在 毁灭 这是否意味着路由器出口在实例化product-list.component后正在激活该组件,导致其在屏幕上呈现?如果是这样的话,为什么顶部栏被留在路由器出口之外?为什么不让路由器插座激活顶部栏 以下是app.component.html: 通常,如果您

我目前正在阅读Angular getting started文档中的代码:

我在app.component.html中看到顶栏.component是如何呈现的,因为它说:

路由器出口将在任何时候启动新组件时发出激活事件 正在实例化,并且在 毁灭

这是否意味着路由器出口在实例化product-list.component后正在激活该组件,导致其在屏幕上呈现?如果是这样的话,为什么顶部栏被留在路由器出口之外?为什么不让路由器插座激活顶部栏

以下是app.component.html:


通常,如果您像这样调用选择器,那么它将调用该组件,但在本例中,下面的代码正在实例化产品组件:

 RouterModule.forRoot([
      { path: '', component: ProductListComponent },
    ])

因此,在激活产品组件时,有两种不同的方法可以将html调用到主页app.component.html

第一个是把html放在索引中,你不能改变它,你会一直看到那个页面

在您的组件中,有如下代码:

@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css']
})
您必须在html中使用调用选择器:

<app-header></app-header>
然后必须在变量中定义路由:

const routes: Routes= [
{path: '', redirectTo:'/clientes', pathMatch: 'full'},
{path: 'product', component: NameComponent}];
import { HeaderComponent } from './header/header.component';
const routes: Routes= [
{path: '', redirectTo:'/clientes', pathMatch: 'full'},
{path: 'product', component: NameComponent}];