Giter VIP home page Giter VIP logo

Comments (10)

devconcept avatar devconcept commented on June 12, 2024

Edit the issue and add a code sample or specify hoy I can reproduce your problem. Without that information it is not possible to know what is going on in your code.

from ng-shopping-cart.

Alessandroinfo avatar Alessandroinfo commented on June 12, 2024

Edit the issue and add a code sample or specify hoy I can reproduce your problem. Without that information it is not possible to know what is going on in your code.

Thank in advance for ng-shopping-cart i really appreciate it!
Now i update my issue with more code.

from ng-shopping-cart.

devconcept avatar devconcept commented on June 12, 2024

You are importing the module incorrectly. You must use forRoot or forChild to remove the warning. Older versions of Angular play well with just referencing the module. It doesn't work the same way for recent Angular versions.

Check https://devconcept.github.io/ng-shopping-cart/guide/get-started#configuring for more information.

from ng-shopping-cart.

Alessandroinfo avatar Alessandroinfo commented on June 12, 2024

You are importing the module incorrectly. You must use forRoot or forChild to remove the warning. Older versions of Angular play well with just referencing the module. It doesn't work the same way for recent Angular versions.

Check https://devconcept.github.io/ng-shopping-cart/guide/get-started#configuring for more information.

When i import shoppingcart with .forChild in the sharedModule i get this error in the export field:

image
And when i import the component in a module loaded in lazy mode i get this error:
image

and i get this error:

ERROR Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[NavbarComponent -> CartService]: StaticInjectorError(Platform: core)[NavbarComponent -> CartService]: NullInjectorError: No provider for CartService! NullInjectorError: StaticInjectorError(AppModule)[NavbarComponent -> CartService]: StaticInjectorError(Platform: core)[NavbarComponent -> CartService]: NullInjectorError: No provider for CartService! at NullInjector.get (http://localhost:5500/vendor.js:64338:27) at resolveToken (http://localhost:5500/vendor.js:64665:24) at tryResolveToken (http://localhost:5500/vendor.js:64591:16) at StaticInjector.get (http://localhost:5500/vendor.js:64454:20) at resolveToken (http://localhost:5500/vendor.js:64665:24) at tryResolveToken (http://localhost:5500/vendor.js:64591:16) at StaticInjector.get (http://localhost:5500/vendor.js:64454:20) at resolveNgModuleDep (http://localhost:5500/vendor.js:86102:29) at NgModuleRef_.get (http://localhost:5500/vendor.js:87190:16) at resolveNgModuleDep (http://localhost:5500/vendor.js:86102:29)

from ng-shopping-cart.

devconcept avatar devconcept commented on June 12, 2024

Do you imported it as well in the AppModule with the forRoot function?

Check the docs https://angular.io/guide/ngmodule-faq#what-is-the-forroot-method

You have to specify the type of your MODULES instead of let the compiler to infer it for you

const MODULES: any[] = [

like this

from ng-shopping-cart.

Alessandroinfo avatar Alessandroinfo commented on June 12, 2024

Yes i've import as forRoot() in AppModule :

@NgModule({
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    SharedModule.forRoot(),
    ShoppingCartModule.forRoot({
      itemType: TourCartItem,
      serviceType: 'localStorage',
      serviceOptions: {storageKey: 'ToursCart', clearOnError: true},
    }),
    CoreModule
  ],
  providers: [],
  bootstrap: [CoreComponent]
})
export class AppModule {
  constructor() {
    if (!environment.production) {
      console.log('app');
    }
  }
}

Now i've added this like you explained:

const MODULES: any = [
  CommonModule,
  HttpClientModule,
  MaterialModule,
  FormsModule,
  ShoppingCartModule.forChild()
];
export class SharedModule {
  constructor() {
    if (!environment.production) {
      console.log('shared');
    }
  }

  static forRoot(): ModuleWithProviders {
    return {
      ngModule: SharedModule,
      providers: [
        ApiService,
        GenericFacilityService,
        {
          provide: ErrorHandler,
          useClass: ErrorsHandlerService
        },
        {
          provide: HTTP_INTERCEPTORS,
          useClass: LoaderInterceptorService,
          multi: true // PERMIT TO USE MULTI INTERCEPTOR FOR HTTP INTERCEPTORS
        }
      ]
    };
  }
}

But i receive this error:

compiler.js:2175 Uncaught Error: Unexpected value '[object Object]' exported by the module 'SharedModule'
    at syntaxError (compiler.js:2175)
    at compiler.js:19668
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.getNgModuleMetadata (compiler.js:19666)
    at CompileMetadataResolver.getNgModuleSummary (compiler.js:19569)
    at compiler.js:19651
    at Array.forEach (<anonymous>)
    at CompileMetadataResolver.getNgModuleMetadata (compiler.js:19629)
    at JitCompiler._loadModules (compiler.js:25402)
    at JitCompiler._compileModuleAndComponents (compiler.js:25385)

Thanks in advance for your support.

from ng-shopping-cart.

devconcept avatar devconcept commented on June 12, 2024

Why are you using forRoot in your own SharedModule? The forRoot and forChild method are used when you declare a module that requires configuration. This is not the case for your SharedModule which can be easily configured using InjectionToken if you ever need it.

Anyway those are errors related to your own code and not the library itself.

from ng-shopping-cart.

Alessandroinfo avatar Alessandroinfo commented on June 12, 2024

You mean the .forRoot() of my SharedModule? I use it for heave a singleton services that are imported in the static method forRoot. Now i know that is a problem related to my code, can you help me to resolve the error i receive Unexpected value '[object Object]'...?

from ng-shopping-cart.

devconcept avatar devconcept commented on June 12, 2024

Sure, remove the forRoot method from your SharedModule and use the @NgModule metadata to declare your components and services as usual.

Declare your services using the providedIn keyword.

@Injectable({
  providedIn: 'root',
})

Check https://stackoverflow.com/a/53008692/4015449

from ng-shopping-cart.

devconcept avatar devconcept commented on June 12, 2024

This section explains why I had to use the forRoot method

https://devconcept.github.io/ng-shopping-cart/guide/the-cart-service#custom-cart-service

from ng-shopping-cart.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.