nebular icon indicating copy to clipboard operation
nebular copied to clipboard

How to use only one component without applying the whole theme styles to the application?

Open henryyue2010 opened this issue 5 years ago • 14 comments

I am trying to use NbChatComponent in my Angular application without applying the whole Nebular theme styles. How to get the default nebular style only apply to the Angular component which uses NbChatComponent? Any samples? Thank you very much in advance for your help. Henry

henryyue2010 avatar Jun 30 '19 05:06 henryyue2010

Hi @henryyue2010. You can do this by calling mixins for individual components inside nb-install. Since chat is using a button, input and icon components under the hood you need to include styles for these components as well. Also, you need to keep track of module dependencies added in the future as it potentially could require more styles to be added.

To sum up:

  1. Setup custom theming. You can skip modifying theme variables if you don't need to.
  2. Change styles.scss to have styles in nb-install only for the chat and it's dependencies:
@include nb-install() {
  @include nb-chat-theme();
  @include nb-icon-theme();
  @include nb-buttons-theme();
  @include nb-input-theme();
};

yggg avatar Jul 22 '19 13:07 yggg

Hi @yggg , I'm trying to do exactly the same thing, ie import the component chat only into a component. I use for the rest of my Material Angular application and it seems that the 2 comes into conflict (it's a shame). I did what you said but I'm still full of error type ERROR TypeError: Can not read property 'appendChild' of undefined, distorted images, ... How to really limit nebular to a single component?

filol avatar Aug 31 '19 18:08 filol

Me too, I am having the same problem and I really need and answer How to really limit nebular to a single component?

AmmarIsmaeel avatar Dec 16 '19 13:12 AmmarIsmaeel

Me too, I am having the same problem and I really need and answer How to import the chat component only into my application without applying the whole theme styles to the application?

el7or avatar Jan 11 '20 12:01 el7or

You can use Angular Elements (Web components)

dinohorvat avatar Jan 13 '20 00:01 dinohorvat

Me too, I am having the same problem and I really need and answer How to import the chat component only into my application without applying the whole theme styles to the application?

Hi, there is how I use only one component for project without apply style to another component.

  • First: install it normally by running ng add @nebular/theme or by manually.
  • Second: if you install it by running command then go to AppModule and AppComponent, revert what nebular added to your template like this one
 <nb-layout>
      <nb-layout-header fixed>Company Name</nb-layout-header>
      <nb-sidebar>Sidebar Content</nb-sidebar>
      <nb-layout-column>
        Page Content <button nbButton>Hello World</button>
      </nb-layout-column>
    </nb-layout>
  • After this, you can use nebular component by grab it between, remember import nb-layout, nb theme module too
 <nb-layout>
      <nb-layout-column>
 <Your nebular HTML go here>
      </nb-layout-column>
    </nb-layout>

P/S: there will be redundant over there and there but at least nebular style will not apply over other component of your project. Maybe better solution out there, better keep looking :eyes:

KagariSan avatar Feb 06 '20 08:02 KagariSan

For those dealing with the problem Nebular causes with ERROR TypeError: Can not read property 'appendChild' of undefined while trying to use just a single Nebular component, there's an easy fix I just found.

Go to your app.module.ts and in the providers array (add one if you don't have one) add { provide: OverlayContainer } and it should fix the issue for the most part.

Alec2435 avatar Aug 17 '20 21:08 Alec2435

For those dealing with the problem Nebular causes with ERROR TypeError: Can not read property 'appendChild' of undefined while trying to use just a single Nebular component, there's an easy fix I just found.

Go to your app.module.ts and in the providers array (add one if you don't have one) add { provide: OverlayContainer } and it should fix the issue for the most part.

You save my date 👍

My Angular Tree

truonghoangduy avatar May 13 '21 07:05 truonghoangduy

I have managed to solve this. See here.

tegola avatar Jun 08 '21 11:06 tegola

For those dealing with the problem Nebular causes with ERROR TypeError: Can not read property 'appendChild' of undefined while trying to use just a single Nebular component, there's an easy fix I just found.

Go to your app.module.ts and in the providers array (add one if you don't have one) add { provide: OverlayContainer } and it should fix the issue for the most part.

Wow! That worked.

Thank you!

eliasmatheus avatar Jul 20 '21 15:07 eliasmatheus

For those dealing with the problem Nebular causes with ERROR TypeError: Can not read property 'appendChild' of undefined while trying to use just a single Nebular component, there's an easy fix I just found. Go to your app.module.ts and in the providers array (add one if you don't have one) add { provide: OverlayContainer } and it should fix the issue for the most part.

You save my date 👍

My Angular Tree

Thank you!!

CleydermanG avatar Sep 03 '21 03:09 CleydermanG

// this is our just created themes.scss file, make sure the path to the file is correct
@use 'themes' as *;

// framework component styles
@use '@nebular/theme/styles/globals' as *;

// install the framework styles
@include nb-install() {
  @include nb-popover-theme();
}

I just want to use the popover-component at the moment. With the provided solution, I get a "Undefined mixin." error.

Does someone have an idea to solve this?

engo2002 avatar May 24 '22 09:05 engo2002

Hi @henryyue2010

Solved

1. add this line in imports of app.module.ts

imports: [  
    NbThemeModule.forRoot({ name: 'default' }),
]

2.app.component.html ;

<nb-layout>
	<nb-layout-column>
		<main>
			<router-outlet></router-outlet>
		</main>
	</nb-layout-column>
</nb-layout>

3. Make sure that the following code is part of styles.scss ;

@use 'themes' as *;
@use '@nebular/theme/styles/globals' as *;
@include nb-install() {
  @include nb-theme-global();
};

4. themes.scss ;

@forward '@nebular/theme/styles/theming';
@use '@nebular/theme/styles/theming' as *;
@use '@nebular/theme/styles/themes/default';

$nb-themes: nb-register-theme((
  // add your variables here like:
  // color-primary-100: #f2f6ff,
  // color-primary-200: #d9e4ff,
), default, default);

5. in app.component.ts add this piece of code in ngOnInit()

  ngOnInit(): void {
      this.router.events.subscribe((event) => {
          document.body.classList.remove('nb-theme-default');
      });
  }
  • This will remove the nebular theme from all the app.

6. in the component you want to apply the theme add this in ngOnInit()

  ngOnInit(): void {
    document.body.classList.add('nb-theme-default');
  }
  • This will add the nebular theme @ the current component.

AhmedMansour92 avatar Jul 14 '22 21:07 AhmedMansour92

I solved it by doing this

jonkenobi avatar Aug 24 '22 05:08 jonkenobi