Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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
Javascript 基于管线角度的显示元素_Javascript_Angular - Fatal编程技术网

Javascript 基于管线角度的显示元素

Javascript 基于管线角度的显示元素,javascript,angular,Javascript,Angular,我很难根据我想要的路线使导航栏设置显示:无。我确实成功订阅了该路线,但我无法将其显示与此关联 到目前为止,我有: 导出类AppComponent实现OnInit{ jwtHelper:jwtHelper=newjwthelper(); 公共场所=''; 构造函数(专用authService:authService,专用路由器:路由器,专用http:http){ this.location=router.url; this.router.events.subscribe((位置)=>{ 控制台日志

我很难根据我想要的路线使导航栏设置显示:无。我确实成功订阅了该路线,但我无法将其显示与此关联

到目前为止,我有:

导出类AppComponent实现OnInit{
jwtHelper:jwtHelper=newjwthelper();
公共场所='';
构造函数(专用authService:authService,专用路由器:路由器,专用http:http){
this.location=router.url;
this.router.events.subscribe((位置)=>{
控制台日志(位置);
返回true;
});
}
}
对于我的应用程序component.ts


和html

选择器不能仅在URL为空(即
'/'
路由)时出现,而必须在其他所有路由中可用。有人能帮我吗?

条件渲染

<Component *ngIf="iWant ? true : false" />

看起来像这样


检查一下这个

,这样你就可以基本上利用rxjs的强大功能了。
this.router.events
是一个事件流(称为可观察事件)。 我们可以获取流并将其(
map
)转换为布尔属性。 然后,我们在要切换的组件上设置一个
*ngIf
,如下所示:

<app-nav *ngIf="showNav$ | async"></app-nav>


顺便说一句,不要因为有人对你的问题投了否决票而气馁,这种情况在这里越来越常见,没有解释为什么我把你的问题重新投票了一遍,因为它很有意义,答案对其他人也很有帮助。

对它使用条件渲染恐怕我对angular和js很在行,你能给我一些“如何”的建议吗?它实际上帮了我很大的忙,谢谢你的支持!现在它只出现在一个路由上,我如何使它反向,确保它不只出现在该路由上?我还得到一个错误,
src/app/app.component.ts(23,26):错误TS2339:类型“RouterEvent | RouteConfigLoadStart | ChildActivationStart”上不存在属性“url”。属性“url”在类型“RouteConfigLoadStart”上不存在。
它会破坏任何东西吗?好的,关于第一个:只需调整app.component中的条件-我使用了
.endsWith('/path2')
作为示例。第二个:我认为您必须实际使用
事件['url']
符号或将事件强制转换为NavigationEnd:
(事件作为NavigationEnd)