8

I want to use ngx-avatar in angular standalone component v14.

I use it in the template and I was imported it in the component imports.

But I got error message:

Component imports must be standalone components, directives, pipes, or must be NgModules.

stackblitz

import { AvatarModule } from 'ngx-avatar';

@Component({
  selector: 'my-app',
  standalone: true,
  imports: [AvatarModule, CommonModule],
  template: `
    app works!

    <ngx-avatar class="my-avatar" value="HM"> </ngx-avatar>
  `,
})
export class AppComponent {
  name = 'Angular ' + VERSION.major;
}

I try to solve it using importProvidersFrom but it's not work:

bootstrapApplication(
  AppComponent, {
   providers: [importProvidersFrom(AvatarModule.forRoot())],
  }
);

Any idea how I can make it work?

kian
  • 1,449
  • 2
  • 13
  • 21
Jon Sud
  • 10,211
  • 17
  • 76
  • 174

3 Answers3

0

From what I found while having a related problem, it seems like the module is malformed.

I'd would guess that the module needs to be compiled with Angular 14+ to be imported as standalone. ngx-avatar isn't since it hasn't been updated for over 2 years.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
0

I can solve this problem, importing a "SharedModule" with the dependencies you need, later if you need to add stuff, you can do it from this module.

The code of SharedModule, could be:

import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AvatarModule } from 'ngx-avatar';
@NgModule({
  exports: [AvatarModule],
  imports: [HttpClientModule, AvatarModule],
})
export class SharedModule {}

Finally you just have to import the SharedModule It works for me

-1

for angular u must import this inside main.ts

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - [From Review](/review/low-quality-posts/34924088) – user16217248 Sep 02 '23 at 01:35