首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >原生脚本(角度2) -隐藏特定组件中的某些app.component.html行

问原生脚本(角度2) -隐藏特定组件中的某些app.component.html行
EN

Stack Overflow用户
提问于 2019-02-02 01:33:20
回答 2查看 259关注 0票数 0

我想隐藏特定组件的app.component.html的一些行。

我有一个底部导航栏,一些组件需要。有一些组件不应该显示导航栏。有没有办法在我的typescript文件中隐藏特定组件上的这些行?

app.component.html

代码语言:javascript
复制
<Gridlayout rows="*, auto">
    <page-router-outlet row="0"></page-router-outlet>

    <!-- Hide this -->
    <BottomNavigation row="1">
         // Code
    </BottomNavigation>
</GridLayout>
EN

回答 2

Stack Overflow用户

发布于 2019-02-02 03:16:37

您可以创建一个可观察的数据服务,以返回一个布尔值来切换BottomNavigator组件的可见性。

代码语言:javascript
复制
@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();
    }
}

然后在应用程序组件中,您可以订阅侦听该值并切换BottomNavigator组件。

代码语言:javascript
复制
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

代码语言:javascript
复制
this.toggleService.sendMessage(_val);

请找到一个有效的here示例

票数 3
EN

Stack Overflow用户

发布于 2019-02-02 02:49:42

在模板中使用*ngIf并在组件中定义一个布尔变量,如下所示

代码语言:javascript
复制
bottomNav = false;

您可以稍后在component中检查后将其设置为true。并在您的模板中执行以下操作

代码语言:javascript
复制
<Gridlayout rows="*, auto">
<page-router-outlet row="0"></page-router-outlet>
<!-- Hide this -->
<div *ngIf="bottomNav;then showNav"></div>
<ng-template #showNav> 
<BottomNavigation row="1">
// Code
</BottomNavigation>
</ng-template>
</GridLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54484433

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档