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

Problem while setting up Nebular for Angular 18 #3264

Open
1 of 2 tasks
erickfigueiredo opened this issue Aug 20, 2024 · 2 comments
Open
1 of 2 tasks

Problem while setting up Nebular for Angular 18 #3264

erickfigueiredo opened this issue Aug 20, 2024 · 2 comments

Comments

@erickfigueiredo
Copy link

erickfigueiredo commented Aug 20, 2024

Issue type

I'm submitting a ... (check one with "x")

  • bug report
  • feature request

Issue description

Current behavior:

I'm setting up Nebular in an Angular 18 standalone application, but I'm having trouble getting the styles from the library to apply.

Expected behavior:

The expected behavior was that the styles and components from the library would work in the application.

Steps to reproduce:

With Angular 18 (using standalone components + css config) I'm just following the setup steps available in the docs, it's a clear project.

Related code:

Here is my code:

angular.json

{
...
"styles": [
              "src/styles.css",
              "node_modules/@nebular/theme/styles/prebuilt/default.css"
            ],
...
}

app.config.ts

import { ApplicationConfig, importProvidersFrom, provideZoneChangeDetection } from '@angular/core';
import { provideRouter } from '@angular/router';
import { NbThemeModule } from '@nebular/theme';

import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
  providers: [
    importProvidersFrom(NbThemeModule.forRoot({name: 'default'})),
    provideZoneChangeDetection({ eventCoalescing: true }),
    provideRouter(routes)
  ]
};

chat.component.ts

import { Component } from '@angular/core';
import { NbLayoutModule, NbChatModule } from '@nebular/theme';


@Component({
  selector: 'app-chat',
  standalone: true,
  imports: [
    NbChatModule,
    NbLayoutModule
  ],
  templateUrl: './chat.component.html',
  styleUrl: './chat.component.css'
})
export class ChatComponent {

  messages: any[] = [
    {
      text: 'Drag & drop a file or a group of files.',
      date: new Date(),
      reply: true,
      user: {
        name: 'Bot',
        avatar: 'https://i.gifer.com/no.gif',
      },
    },
  ];

  sendMessage(event:any) {
    const files = !event.files ? [] : event.files.map((file:any) => {
      return {
        url: file.src,
        type: file.type,
        icon: 'file-text-outline',
      };
    });

    this.messages.push({
      text: event.message,
      date: new Date(),
      files: files,
      type: files.length ? 'file' : 'text',
      reply: true,
      user: {
        name: 'Jonh Doe',
        avatar: 'https://i.gifer.com/no.gif',
      },
    });
  }
}

chat.component.html

<nb-layout>
  <nb-layout-column>
    <nb-chat title="Drag & Drop chat" size="medium">
      <nb-chat-message
        *ngFor="let msg of messages"
        [type]="msg.type"
        [message]="msg.text"
        [reply]="msg.reply"
        [sender]="msg.user.name"
        [date]="msg.date"
        [files]="msg.files"
        [avatar]="msg.user.avatar"
      >
      </nb-chat-message>
      <nb-chat-form
        (send)="sendMessage($event)"
        [dropFiles]="true"
      ></nb-chat-form>
    </nb-chat>
  </nb-layout-column>
</nb-layout>

Here's what I'm getting:
image

Other information:

npm, node, OS, Browser

OS: Windows 11
Browser: Chrome
Node: v20.16.0

Angular, Nebular

Angular: 18
Nebular: 14
@NXFinity
Copy link

NXFinity commented Aug 23, 2024

Take out

"node_modules/@nebular/theme/styles/prebuilt/default.css"

image

From your angular.json

and add the following to your style.css

image

@import 'themes';

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

Create a themes.css in same folder as the style.css and add

image

// @nebular theming framework
@import '@nebular/theme/styles/theming';
// @nebular out of the box themes
@import '@nebular/theme/styles/themes';

$nb-themes: nb-register-theme((), default, default);

It should then work as intended, if not just change all .css extensions to .scss.

I use scss and this is my configuration.

You'll also need to import NbThemeModule and NbLayoutModule

image

I'm also not using standalone.

@salarenko
Copy link

@erickfigueiredo I do not recommend setting up new projects with this library. It had some potential, but due to no maintenance and lack of migration towards new Angular features this is just outdated and in some places bugged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants