angular - Nativescript (Angular 2) - 在特定组件中隐藏 app.component.html 的一些行
问题描述
我想为特定组件隐藏 app.component.html 的一些行。
我有一些组件需要的底部导航栏。有些组件不应该显示导航栏。有什么方法可以将这些行隐藏在我的打字稿文件中的特定组件上?
app.component.html
<Gridlayout rows="*, auto">
<page-router-outlet row="0"></page-router-outlet>
<!-- Hide this -->
<BottomNavigation row="1">
// Code
</BottomNavigation>
</GridLayout>
解决方案
您可以创建一个可观察数据服务,以返回一个布尔值来切换BottomNavigator
组件的可见性。
@Injectable()
export class MessageService {
private subject = new Subject<Boolean>();
sendMessage(_value: boolean) {
this.subject.next(_value);
}
clearMessage() {
this.subject.next();
}
getMessage(): Observable<Boolean> {
return this.subject.asObservable();
}
}
然后在 App 组件中,可以订阅监听值并切换BottomNavigator
组件。
MessageService.toggleService.subscribe(toShow => {
this.isComponentShown = toShow;
});
// OR if using the prefered async pipe
// https://angular.io/docs/ts/latest/guide/pipes.html
this.isComponentShown = this.toggleService.getMessage();
并且无论您需要显示什么,BottomNavigator
您都可以设置 MessageService
this.toggleService.sendMessage(_val);
请在此处找到一个工作示例
推荐阅读
- php - 是否可以将关联数组转换为多维数组?
- ios - Unity 3d 模型在手机上支离破碎
- selenium - selenium 如何通过 x,y 位置单击按钮
- python - 在 for 循环中修改的附加变量不能按预期工作
- sdl - 如何修复 buildroot Raspberry 映像中的“SDL_Init failed -1”?
- python-3.x - 运行后台任务的最简单方法
- python - 在 Google Places API 搜索中包含多种类型
- go - 使用 defer 时函数中的返回值
- php - Php Calculation 在 multple 和 plus 运算符计算中显示不正确的输出
- javascript - React.js - 将外部 reactjs 文件包含到 html 中