material icon indicating copy to clipboard operation
material copied to clipboard

feat(tabs): add support for ng-show and hide/show layout directives

Open Chidan opened this issue 10 years ago • 18 comments

Hi there,

hide attribute and ng-show doesnt work on , below is what I am trying to do. image

OR image

both dont hide the tab, is there any way to conditional show a tab?

Regards, Chidan

Chidan avatar Sep 03 '15 16:09 Chidan

Can use ng-if:

<md-tab data-ng-if="ctrl.showTab" label="Tab2">Tab2 content</md-tab>

http://codepen.io/anon/pen/RWNZyM

paulflo150 avatar Sep 04 '15 04:09 paulflo150

@paulflo150 thanks for example, yes ng-if works but ng-show, and hide attributes are not working, is this a bug or by design?

Chidan avatar Sep 09 '15 13:09 Chidan

+1 Using ng-if together with $mdMedia to simulate hide attribute as a workaround

ghost avatar Mar 03 '16 19:03 ghost

when ng-if use in <md-tab> then <md-tabs> md-selected not working, is it bug or work another way?

jangidgirish avatar Mar 06 '16 06:03 jangidgirish

Having the same issue, ng-show/hide won't be supported?

mustela avatar Mar 23 '16 09:03 mustela

+1

matt-neill avatar Apr 21 '16 04:04 matt-neill

+1

yevkbb avatar Apr 27 '16 14:04 yevkbb

+1

ganeshghalame avatar May 11 '16 08:05 ganeshghalame

This issue is closed as part of our ‘Surge Focus on Material 2' efforts. For details, see our forum posting @ http://bit.ly/1UhZyWs.

ThomasBurleson avatar Jun 02 '16 13:06 ThomasBurleson

The issue is still present. And ng-if doesn't suit my case. I have ng-controllers inside tabs content and have to init them just once.

Skriptach avatar Jun 29 '16 09:06 Skriptach

+1 the issue is still present.

Beny-Muler avatar Apr 05 '17 14:04 Beny-Muler

This worked for me. You have to modify the source...

In the MdTab directive at appox. line: 34434 Add "hide: '=?ngHide'" to the isolated scope

scope:    {
      active:   '=?mdActive',
      disabled: '=?ngDisabled',
      hide:     '=?ngHide',
      select:   '&?mdOnSelect',
      deselect: '&?mdOnDeselect'
}

then in the MdTabItem directive at appox. line 34496

Add this watch

function MdTabItem () {
  return {
    require: '^?mdTabs',
    link:    function link (scope, element, attr, ctrl) {
      if (!ctrl) return;
      ctrl.attachRipple(scope, element);

      scope.$watch('tab.scope.hide', function (value) {
          if (value)
              element.css('display', 'none');
          else
              element.css('display', 'block');
      });
    }
  };
}

smithscripts avatar Apr 21 '17 16:04 smithscripts

@smithscripts wroks perfect !!! Thanks

Avishaidev avatar Jul 06 '17 11:07 Avishaidev

its so annoying, so many controls are just unperfect and broken in some ways... people should think before using this library in serious projects

xzessmedia avatar Aug 07 '17 13:08 xzessmedia

Just ran into a related bug where controls on an md-tab with the ng-if directive and no default value are not bound properly. Tested Angular 1.5.7 (don't ask...) and 1.7.2. My solution was to use the ng-disabled directive and a bit of css:

.md-tab.md-disabled { display:none; }

Not helpful if you use ng-disabled as intended of course.

tkegan avatar Aug 06 '18 18:08 tkegan

I have re-opened this issue to indicate that we would welcome a community contribution to add this functionality to the tabs component.

Splaktar avatar Aug 09 '18 01:08 Splaktar

@Splaktar there's already a contribution to this, @smithscripts did it https://github.com/angular/material/issues/4456#issuecomment-296236790

BaldemarJanrain avatar Aug 09 '18 19:08 BaldemarJanrain

@BaldemarJanrain right, I see that, but we need a PR for it, not just a comment. Also instead of using a watch in all cases, we would use a MutationObserver for improved performance (example here).

If you would like to submit a PR, I would be happy to help you with it.

Splaktar avatar Sep 20 '18 19:09 Splaktar