valor-software / ngx-bootstrap

Fast and reliable Bootstrap widgets in Angular (supports Ivy engine)
https://valor-software.com/ngx-bootstrap
MIT License
5.53k stars 1.69k forks source link

unable to set theme to bootstrap4 with systemjs #507

Closed mjhugo closed 8 years ago

mjhugo commented 8 years ago

When using SystemJS, you cannot switch the theme to Bootstrap 4 via the recommended method:

import {Ng2BootstrapConfig, Ng2BootstrapTheme} from 'ng2-bootstrap/ng2-bootstrap';

Ng2BootstrapConfig.theme = Ng2BootstrapTheme.BS4;

enableProdMode();

 bootstrap(AppComponent);

When this is done, the AppComponent will recognize the BS4 theme, but the ng2 components will not.

As an example, clone https://github.com/mjhugo/angular2-quickstart (which has been updated to bs4 theme, see https://github.com/mjhugo/angular2-quickstart/commit/953d888991c058dbf75318393367b54c818b627b) and run npm i and npm start and notice that the theme will not be applied correctly

wrong theme

If it had applied the bs4 theme correctly, it should look more like this:

image

As indicated in https://github.com/valor-software/ng2-bootstrap/issues/371 there is a workaround - add this script block and ng2-bootstrap will switch to bootstrap4 theme.

  <script type="text/javascript">
    // temporary hack for enable bootstrap 4
    window.__theme = 'bs4';
  </script>
maxfisher05 commented 8 years ago

this is because Glyphicons is included in bootstrap 3 but not in 4, you are missing the glyphicon-chevron-left and glyphicon-chevron-right icons. I think that it would be nice if ng2-bootstrap had support for changing out icon pack for bs4.

if you are using font-awesome + bs4 you can add css aliases like this (using sass):


.glyphicon {
  @extend .fa;

  &.glyphicon-chevron-left {
    @extend .fa-chevron-left;
  }

  &.glyphicon-chevron-right {
    @extend .fa-chevron-right;
  }

  &.glyphicon-chevron-up {
    @extend .fa-chevron-up;
  }

  &.glyphicon-chevron-down {
    @extend .fa-chevron-down;
  }
}
valorkin commented 8 years ago

@mjhugo you can check

  <link rel="stylesheet" href="assets/css/style.css">
  <link rel="stylesheet" href="assets/css/glyphicons.css">

from demo folder

but I am completely agreed with @maxfisher05 And I working on more simple template switching

valorkin commented 8 years ago

@mjhugo please close an issue if @maxfisher05 answer was helpful

mjhugo commented 8 years ago

Thanks for the feedback and suggestion.

I tried adding glyphicons but still no luck. (https://github.com/mjhugo/angular2-quickstart/commit/eb6c1acb6cb0fd9e354763d49821f0d5d3b64ffe) so I don't think that's the actual issue. You're correct that the glyphicons are missing in my screen shot - but also notice that the CSS styling is BS3 styles, not BS4.

If you set a debugging breakpoint in the DATEPICKER_DIRECTIVES and check the value of Ng2BootstrapConfig.theme you will find that it still set to BS3 instead of BS4. My guess is that the ng2 components are initializing before AppComponent and as such, they are initialized with a theme of BS3 before the AppComponent changes the theme to BS4.

alexciesielski commented 8 years ago

+1 for way of changing icon package, I would like to use FontAwesome instead of Glyphicons.

hongbo-miao commented 8 years ago

Similar here, I am using Typeahead.

import { Ng2BootstrapConfig, Ng2BootstrapTheme } from 'ng2-bootstrap/ng2-bootstrap';
Ng2BootstrapConfig.theme = Ng2BootstrapTheme.BS4;

does not work for me, it gives me bad style: image

But

  <script type="text/javascript">
    window.__theme = 'bs4';
  </script>

gives me good style: image

searchforac commented 8 years ago

The daypicker left right buttons seem to show text arrows instead of the cheveron glyphicons that are on the monthpicker and yearpicker. This is also the case in the example. I've tried setting the ARROW_LEFT and ARROW_RIGHT variables to the icons instead of &lt and &gt but that doesn't change anything. What am I missing?

I was able to get the glyphicons to show by using the script workaround and downloading the glyphicons.

screen shot 2016-08-18 at 11 15 30 am screen shot 2016-08-18 at 11 15 42 am

fstof commented 8 years ago

@searchforac I can confirm this issue, It seems the glyphicons-chevron-left/right were replaced with > and < on the day page but the month and year are still using the glyphicons

would be great if this can be sorted out, seems simple enough

cfm017 commented 8 years ago

+1

StealthyDev commented 8 years ago

Is there a fix or workaround for this issue? How does it work in DEMO page?

tommiv commented 8 years ago

@StealthyDev, it's in the first message of this thread

<script type="text/javascript">
    // temporary hack for enable bootstrap 4
    window.__theme = 'bs4';
</script>
StealthyDev commented 8 years ago

Sorry, I tried this. I'm also using WebPack.

tommiv commented 8 years ago

It worked for me, but i've tried it while ago. Btw, it doesn't matter if you use WebPack, since Webpack just bundles your code. You still need to include target bundle in page <head>. Just make sure you put workaround script above the webpack bundle.

valorkin commented 8 years ago

This hack was written a long long time ago Now I can switch to 'forRoot' method to choose app theme

StealthyDev commented 8 years ago

How do you do it?

valorkin commented 8 years ago

You can check our demo page source https://github.com/valor-software/ng2-bootstrap/blob/development/demo/index-bs4.html

StealthyDev commented 8 years ago

Yes, it fixed it. Thank you.