【发布时间】:2019-06-27 05:07:53
【问题描述】:
通常对我来说一切正常,当我运行 ng build 时,我的代码继续正常运行,并且事件被触发 (activate)。但是在执行ng build --prod 时,此事件不会运行。为什么这会发生在我身上,我该如何纠正?
谢谢
这段代码是我的 app.ts 和 .html
<menu class="m-0 p-0" *ngIf="hide"></menu>
<router-outlet class="m-0 p-0" (activate)='onActivate($event)' ></router-outlet>
<footer_component *ngIf="hide"></footer_component>
onActivate(component:any){
this.activatedComponent = component.constructor.name;
之前用ng build编译可以,运行ng build之后也可以,但是用ng build --prod不行,好像没有进入函数。
console.log(activatedComponent);
if(this.activatedComponent != 'LoginComponent' && this.activatedComponent != 'RestorePasswordComponent' && this.activatedComponent != 'NotFoundComponent'){
this.hide = true;
} else
{
this.hide = false;
}
}
【问题讨论】:
-
所以即使
console.log(activatedComponent);也不会发生? -
你可以订阅 Angular 的路由器
events可观察流并使用 URL 来切换hide标志。
标签: angular