Trouble with styling the Ngx-org-chart in Angular

I integrated the ngx-org-chart library into my Angular project, but I'm facing issues with the styles not applying correctly.

Here are the steps I followed:

  1. I first installed the package using:

yarn add ngx-org-chart

  1. Then, I added the ngx-org-chart imports to the styles block in angular.json:

    "styles": [ 
              "node_modules/ngx-org-chart/_theming.scss",
              "src/styles.scss"
    ],
    

Even after doing this, the styles were still not applied. I also tried:

  1. I imported the styles in styles.scss using:
import '~ngx-org-chart/_theming.scss'

Unfortunately, the styles are still not working. Can anyone assist me with this issue? Thank you.

Edit

In my component, I have included the following line of code to utilize the library:

<ngx-org-chart [nodes]="nodes" direction="vertical"></ngx-org-chart>

The 'nodes' data structure looks like this:

nodes: any = [
    {
      name: 'Sundar Pichai',
      cssClass: 'ngx-org-ceo',
      image: '',
      title: 'Chief Executive Officer',
      childs: [
        {
          name: 'Thomas Kurian',
          cssClass: 'ngx-org-ceo',
          image: 'assets/node.svg',
          title: 'CEO, Google Cloud',
        },
        ...
];

In app.module.ts, my setup includes:

@NgModule({
  declarations: [
    AppComponent,
    EmptyRouteComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    CommonModule,
    ThemeModule,
    I18NextModule.forRoot(),
    NgxOrgChartModule
  ],
  providers: [
    ...
  ],
  bootstrap: [AppComponent]
})

Edit 2

Despite trying various solutions, the chart is displaying incorrectly as shown here:

https://i.sstatic.net/1LW91.png

It should actually appear like this:

https://i.sstatic.net/yNBeU.png

Versions:

  • ngx-org-chart: 1.1.1
  • Angular: 11.0.5

Answer №1

I inserted

@import '~ngx-org-chart/_theming';
into my styles.scss file.

Added

import { NgxOrgChartModule } from 'ngx-org-chart';
to the app.module.ts like this:

    @NgModule({
        imports: [BrowserModule, FormsModule, NgxOrgChartModule],

In the html code, I included:

<ngx-org-chart [nodes]="nodes" direction="vertical" ></ngx-org-chart>

Unfortunately, I have not imported the assets yet.

https://i.sstatic.net/xKhF9.png

Answer №2

Give this a shot in your styles file: add '../node_modules/ngx-org-chart/_theming.scss';

Answer №3

In addition to the information provided in the documentation found at https://www.npmjs.com/package/ngx-org-chart

I successfully resolved my issue by including the following code snippet into my angular.json file:

 styles: [
          "src/styles.css",
          "node_modules/ngx-org-chart/_theming.scss"
        ],

This solution worked perfectly for me.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring Angular: How to Access HTTP Headers and Form Data from POST Request

I am currently working with an authentication system that operates as follows: Users are directed to a third-party login page Users input their credentials The website then redirects the user back to my site, including an auth token in a POST request. Is ...

There are several InputBase elements nested within a FormControl

There seems to be an issue: Material-UI: It appears that there are multiple InputBase components within a FormControl, which is not supported. This could potentially lead to infinite rendering loops. Please only use one InputBase component. I understand ...

Encountering an issue with core.js:15723 showing ERROR TypeError: Unable to access property 'toLowerCase' of an undefined value while using Angular 7

Below, I have provided my code which utilizes the lazyLoading Module. Please review my code and identify any errors. Currently facing TypeError: Cannot read property 'toLowerCase' of undefined in Angular 7. Model Class: export class C_data { ...

What imports are needed for utilizing Rx.Observable in Angular 6?

My goal is to incorporate the following code snippet: var map = new google.maps.Map(document.getElementById('map'), { zoom: 4, center: { lat: -25.363, lng: 131.044 } }); var source = Rx.Observable.fromEventPattern( function (han ...

How can I transfer data to a different component in Angular 11 that is not directly related?

Within the home component, there is a line that reads ...<app-root [message]="hii"> which opens the app-root component. The app-root component has an @input and {{message}} in the HTML is functioning properly. However, instead of opening t ...

Is there a way to access a file from an S3 bucket URL using Angular?

Currently, I have the URL but I'm not interested in putting in the effort to retrieve the file data or blob. This is my current approach: const url = 'https://s3-us-west-1.amazonaws.com/....'; const a: any = document.createElement('a& ...

reusable angular elements

I'm facing a situation where I have a search text box within an Angular component that is responsible for searching a list of names. To avoid code duplication across multiple pages, I am looking to refactor this into a reusable component. What would b ...

execute the function once the filereader has completed reading the files

submitTCtoDB(updateTagForm:any){ for(let i=0;i<this.selectedFileList.length;i++){ let file=this.selectedFileList[i]; this.readFile(file, function(selectedFileList) { this.submitTC(updateTagForm,selectedFileList); }); } } } ...

What is the syntax for assigning a public variable within a TypeScript function?

I am finding it challenging to assign a value to a public variable within another function. I seem to be stuck. export class MyClass{ myVar = false; myFunction(){ Module.anotherFunction(){ this.myVar = true; } } } ...

To handle async actions in Typescript with React and Redux, ensure that all actions passed to axios are plain objects. If you need to perform

Looking for assistance with Typescript, React, and Redux. export function fetchAllMeals (subject: string){ axios .get(`https://www.themealdb.com/api/json/v1/1/search.php?s=${subject}`) .then((response: any) => { console.log(response.data) ...

Exploring the Wonderful World of Styled Components

I have a query regarding styled components and how they interact when one is referenced within another. While I've looked at the official documentation with the Link example, I'm still unclear on the exact behavior when one styled component refe ...

Error: Unable to locate the tslint command

After attempting to utilize tslint --fix, I encountered the error message bash: tslint: command not found.... To install tslint, I ran the following command: yarn global add tslint typescript. The operating system on my machine is Centos 7. ...

The TypeScript declaration for `gapi.client.storage` is being overlooked

When I call gapi.client.storage.buckets.list(), TypeScript gives me an error saying "Property 'storage' does not exist on type 'typeof client'." This issue is occurring within a Vue.js application where I am utilizing the GAPI library. ...

Compilation error in VueJS: missing dependency detected

I am facing an issue in my VueJS project where a file I am referencing seems to be causing a compilation error. Despite being present in the node_modules directory, the dependency is declared as not found. In the image on the left, you can see the directo ...

The style fails to load correctly upon the page's initial loading

I am utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4d26282823603e212429283f0d7b63756378">[email protected]</a> in a <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="026c677a76 ...

What are the drawbacks of introducing a dependency within the constructor?

I'm struggling to understand why breaking the rules is considered bad. import {DepClass} from './di-import' // <- some dependency imports here class DI1 { dep1: DepClass constructor(){ this.dep1 = new DepClass() // ...

Type-constrained generic key access for enhanced security

While attempting to create a versatile function that retrieves the value of a boolean property using a type-safe approach, I encountered an issue with the compiler not recognizing the type of my value. type KeyOfType<T, V> = keyof { [P in keyof T a ...

Compilation errors plague TSC on varying systems

After successfully creating a node app in TypeScript and running it locally without any issues, I encountered compilation errors when deploying the app on Heroku: app/api/controllers/ingredient.controller.ts(3,24): error TS2307: Cannot find module & ...

Why does my array seem to update only once in the view?

I am currently working on a project that aims to visually represent sorting algorithms, but I have encountered an issue. In order to effectively visualize the sorting process of an algorithm, it is crucial to display every change in the array as the proc ...

Customizable TypeScript interface with built-in default key value types that can be easily extended

One common pattern that arises frequently in my projects involves fetching values and updating the UI based on the 'requestStatus' and other associated values. type RequestStatus = | 'pending' | 'requesting' | 'succ ...