Problems implementing ng2-img-max lib!

Asked

Viewed 71 times

0

I installed ng2-img-max in order to resize images. I want each image sent to be resized to a predefined width and length. I see that most people use ng2-img-max when developing with angular 2/4. I tried using with that lib and then faced the following error:

Error: Uncaught (in promise): Error: No provider for Ng2PicaService

This error informs that the name of the service needs to be placed in the providers, the problem is that in my project I have not created any service with this name, I am guiding myself for this tutorial below;

Resizing Images in the Browser in Angular With ng2-img-max

I have created a module to store all services regarding the implementation of the image resizer as you can see below;

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ImgMaxPXSizeService } from './img-maxpx-size.service';
import { ImgMaxSizeService } from './img-max-size.service';
import { Ng2ImgMaxService } from './ng2-img-max.service';
import { ImgExifService } from './img-exif.service';
import { Ng2PicaService } from '../../../node_modules/ng2-pica';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [],
  providers: [
    ImgMaxPXSizeService,
    ImgExifService,
    ImgMaxSizeService,
    Ng2ImgMaxService
]
})
export class ImgMaxModule { }

//https://github.com/bergben/ng2-img-max

And the module I published in the file app.modulets.

as you can see below;

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    HttpModule,
    RouterModule,
    SharedModule,
    RestaurantModule,
    AdminModule,
    ImgMaxModule,// >>>>>>> modulo de imagens
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

How could I get around this problem?

I think only people who have ever messed with this lib will be able to help me.

This is my complete repository project github.

REPOSITORY

  • tries to import Imgmaxmodule into the module that you declare its component

  • @Eduardovargas I think that’s not the problem, the problem is the file Ng2PicaService

1 answer

1


You are declaring the providers but did not import the module Ng2ImgMaxModule how it sends the documentation of the link you published.

import { Ng2ImgMaxModule } from 'ng2-img-max';

@NgModule({
  declarations: [AppComponent],
  imports: [
    // ...
    Ng2ImgMaxModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Try to import this module into your ImgMaxModule.

  • Caught, thank you so much for that cool, we were already giving up.. hahahahaha

  • Hahaha happens...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.