Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta 14 NavBar not working with ngClass #2732

Closed
danjohnso opened this issue Dec 16, 2014 · 24 comments
Closed

Beta 14 NavBar not working with ngClass #2732

danjohnso opened this issue Dec 16, 2014 · 24 comments
Milestone

Comments

@danjohnso
Copy link

When using ngClass to dynamically assign the nav bar color, the color is not applied.

ng-class="{ 'bar-assertive': isBarVisible, 'bar-clear': !isBarVisible }"

The class is applied when I use inspector, but something else must not get added in as just assigning bar-assertive works fine.

http://codepen.io/danda1man/pen/dPMBJL

@drewrygh drewrygh added css needs: reply the issue needs a response from the user labels Dec 19, 2014
@drewrygh
Copy link
Contributor

Confirmed, working in beta-13

How are you using this? Are you switching the css class when you switch views, or is it being changed within a view? If you have are switching views, it may be easier to use a unique navbar for each view, see the "Alternate Usage" section of the navbar docs for an example.

@danjohnso
Copy link
Author

I was using it on a view change , I did end up using a different navbar to work around it

@Ionitron Ionitron removed the needs: reply the issue needs a response from the user label Jan 19, 2015
@vader-dvt
Copy link

Having same problem :

is not displaying the selected color (yet the class is correctly being added to the view)

Just bellow I use :

and it it working as expected for the menu's header color.

@mvidailhet
Copy link

Having the same issue here with beta14. Even if the var is on the rootScope, the class is never changed.

@mvidailhet
Copy link

For those looking for a workaround until it's fixed, you can achieve this by adding or removing manually the class from the ion-nav-bar element:

var element = angular.element(document.querySelector('ion-nav-bar'));

element.addClass('your-class');

If you want to change the class when changing views, you can listen to the event $stateChangeStart on the rootScope:

$rootScope.$on('$stateChangeStart',
    (event, toState, toParams, fromState: any, fromParams): void => {
        // change class here
    });

Hope this helps

@vader-dvt
Copy link

Mhmm... it didn't even do the trick with your code in my controller ...

@timcosta
Copy link

I believe this is also an issue with ngStyle. Using ion-nav-bar.nav-title-slide-ios7(ng-style="{'background-color':GlobalConfig.baseHex}") I can inspect the element in chrome and see that the background-color has been applied to ion-nav-bar, but it is not visible on the background that is actually in view.

@reviyou
Copy link

reviyou commented Mar 11, 2015

Looks like it's an issue with release candidate as well, would be nice to hear back from ionic team about plans to address it hopefully. Workaround gets ugly very fast especially if you have caching and different styles for different pages - you should be mindful about which navigation bar you are trying to change our of 10 cached ones etc...

@JoeKomputer
Copy link

+1 I am running into this problem with rc.1

@michaeljonathan
Copy link

+1

I am getting this on Ionic 1.0.0. Having ngClass on the ion-nav-bar works perfectly fine DOM-wise (properly updates the classes on ion-nav-bar) but it doesn't update the classes of the Ionic generated element(s) ion-nav-bar > .nav-bar-block > ion-header-bar.

alvarowolfx added a commit to alvarowolfx/ionic that referenced this issue Jun 6, 2015
Fixes ionic-team#2732

When I was developing a app I needed to change the navbar color depending on the screen. I tried using the rootScope workaround just like on issue ionic-team#2732 but it didn't worked out because the navbar does not sync with it's inner headerBar. Besides that I feeled that this was not the best way to do this. I already develop native iOS apps and the navbar has methods to change it's appearance, that why I thought that the best solution is to add the ```appearance``` method to change it.
@ghost
Copy link

ghost commented Jun 12, 2015

+1

Any workaround in the meantime?

@lonormaly
Copy link

+1

@mhartington
Copy link
Member

#3896 should address this, but it won't get merged in until 1.1, being a big change. In the mean time, I have this demo that people can use.

http://codepen.io/mhartington/pen/dozjvv

@mhartington mhartington added this to the 1.1 milestone Jun 19, 2015
@miickel
Copy link

miickel commented Jul 21, 2015

Not sure if this was solved in 1.1, but it sure works for me.

jade

ion-nav-bar(
  ng-class="{ 'bar-transparent': isNavBarTransparent }"
)

css

.bar-transparent .bar.bar-header {
    background: transparent;
}

@mhartington
Copy link
Member

Closing this for now. #3896 will allow this, but will be added in 1.1.

@emilyemorehouse
Copy link

@mhartington, was this added in 1.1? Didn't see it in the changelog.

@mhartington
Copy link
Member

Unfortunately not it was not. Other feature too priority this time around, but as stated in the PR, you can already do this with a little bit of code.

http://codepen.io/mhartington/pen/dozjvv

@emilyemorehouse
Copy link

Yep, I grabbed the directive already. Works great with animations too, thanks!

@nateev
Copy link

nateev commented Dec 16, 2015

Thanks @mhartington for the directive, however how to get it worked with dynamic value like
<ion-view nav-bar-class="bar-{{item.theme}}"> for example ?

@david-bulte
Copy link

@nateev I changed @mhartington's code a bit so you could use it with dynamic values. Mind you, I'm not sure what the "cacheNavBar" in the original solution is (I'm quite new to Ionic) and I left it out. So maybe there is room for improvement.

Here's the directive:

function NavBarClass() {

    var colors = ['positive', 'stable', 'light', 'royal', 'dark', 'assertive', 'calm', 'energized'];

    return {
        restrict : 'A',
        scope : {
            navBarClass : '='
        },
        link : function($scope) {
            var activeNavBar = document.querySelector('.nav-bar-block[nav-bar="active"]');
            var activeHeaderBar = activeNavBar.querySelector('.bar-header');

            cleanUp(activeHeaderBar);
            activeHeaderBar.classList.add('bar-' + $scope.navBarClass);
        }
    }

    function cleanUp(activeHeaderBar) {
        for (var i = 0; i < colors.length; i++) {
            activeHeaderBar.classList.remove('bar-' + colors[i]);
        }
    };

}

And this is how you'd use it:

<ion-view view-title="{{detailsCtrl.productClass.name}}" nav-bar-class="detailsCtrl.getColorClass()">

...where getColorClass() is a method on the Controller.

@theromis
Copy link

theromis commented May 3, 2016

any progress on this issue?

@fahimshekaib
Copy link

I am using Angular1. I wana change the ion-nav-bar color by assigning alternate classes to it to render different colors based on a boolean variable at rootScope level depending on whether the device is set to receive push notification or not. I hope for a solution to ng-class usage issue in ion-nav-bar

@ashishbajaj99
Copy link

any updates?

@maxime1992
Copy link

@david-bulte I don't understand how to use your code and it would really help me :)

Can you give me more details please ?

I do have this :
<ion-nav-bar class="bar-dark" ng-class="menuCtrl.selectedMenu.color">

And the ng-class doesn't work.

I tried to patch ionic with this : 4ab30d2 but it's not working either

Thank you

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.