简体   繁体   English

Angular ngx-bootstrap 隐藏选项卡内容

[英]Angular ngx-bootstrap hide tab content

I have 3 tabs on an Angular 8 page and I'm trying to get one of the tabs to either no longer display or at least to stop displaying its content when a variable equals zero.我在 Angular 8 页面上有 3 个选项卡,我试图让其中一个选项卡不再显示或至少在变量为零时停止显示其内容。 I've tried a few things so far.到目前为止,我已经尝试了几件事。

Here is the tab:这是标签:

<tab heading="{{counter}}" id="counter" [hidden]="counter == 0"></tab>

I tried this with and without the following line in the styles.css and in the component css, as a page I found on the web suggested:我尝试在 styles.css 和组件 css 中使用和不使用以下行,作为我在 Z71567A5EC937056 上找到的页面建议:

[hidden] { display: none !important; }

Here is the variable in the component ts file:这是组件 ts 文件中的变量:

counter: number;

The variable gets set by an array coming in from an API call, this all appears to be working fine:该变量由来自 API 调用的数组设置,这一切似乎工作正常:

this.counter = this.messagesArray.length;

The interpolation on the tab tag works and shows "0" and when logging to the console the count also shows "0" but the conditions in the tab do not hide or change the content.选项卡标签上的插值有效并显示“0”,当登录到控制台时,计数也显示“0”,但选项卡中的条件不会隐藏或更改内容。

I also tried ngClass:我也试过ngClass:

<tab heading="{{counter}}" id="counter" [ngClass]="{'counterHide' : counter == 0}"></tab>

None of these change the tab or its content.这些都不会更改选项卡或其内容。

Do other approaches exist?是否存在其他方法? Has anyone had any success with dynamically altering ngx-bootstrap tabs?有没有人在动态更改 ngx-bootstrap 选项卡方面取得任何成功? Should I try a different tabset?我应该尝试不同的标签集吗?

Thank you!谢谢!

I came across another approach that seems to be working.我遇到了另一种似乎有效的方法。 It makes the tab disappear and does not effect the tab ordering:它使选项卡消失并且不影响选项卡排序:

<tab heading="{{counter}}" id="counter" customClass=countHidden{{ count !=0 ? '_HIDDEN' : '' }}></tab>

Along with the CSS class:与 CSS class 一起:

.countHidden { display: none !important; }

I also needed to put the CSS class in styles.css instead of the individual component's CSS, which I've had to do for most, if not all, of the tab styling. I also needed to put the CSS class in styles.css instead of the individual component's CSS, which I've had to do for most, if not all, of the tab styling.

for specific Index特定索引

.nav-tabs > li:nth-child(tabIndex){
  display: none;
}

for all tabs in a component对于组件中的所有选项卡

.nav-tabs > li{
display:none
}

Specify them in style.css在 style.css 中指定它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM