Coder Social home page Coder Social logo

Comments (11)

jspizziri avatar jspizziri commented on April 20, 2024 1

from angular.

christopherthielen avatar christopherthielen commented on April 20, 2024

Can you post your root module too?

from angular.

jspizziri avatar jspizziri commented on April 20, 2024
//app/app.module.ts

import { LocationStrategy, PathLocationStrategy, Location } from '@angular/common';
import { SystemJsNgModuleLoader, NgModuleFactoryLoader, NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { UIRouterModule, UIRouter } from 'ui-router-ng2';

import FooModule from './foo/foo.module';
import BarModule from './bar/bar.module';
import AppComponent from './app.component';

@NgModule({
  imports: [
    BrowserModule,
    UIRouterModule.forRoot({
      useHash: false,
      config: function uiRouterConfigFn(router: UIRouter) {
        router.urlService.rules.otherwise({ state: 'foo' });
        router.stateRegistry.root();
      },
    }),

    FooModule,
    BarModule,
  ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ],
  providers: [
    { provide: LocationStrategy, useClass: PathLocationStrategy },
    { provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader },
    { provide: Location, useClass: Location },
  ],
})
export class AppModule {}

from angular.

christopherthielen avatar christopherthielen commented on April 20, 2024

OK, that's interesting.
What happens if you change your root module imports (removing FooModule) to:

  imports: [
    BrowserModule,
    UIRouterModule.forRoot({
      useHash: false,
      config: function uiRouterConfigFn(router: UIRouter) {
        router.urlService.rules.otherwise({ state: 'foo' });
        router.stateRegistry.root();
      },
    }),

    BarModule,
  ],

from angular.

jspizziri avatar jspizziri commented on April 20, 2024

Thanks for looking into this!

That does make the error go away, however I'd prefer to not have to do that long term as FooModule also contains functionality which is used by a couple of other modules (e.g. a form or something) If I import FooModule into more than one other module (let's say FooBarModule uses the FooComponent) then the duplicate state error occurs again.

The option of moving the reusable forms into a SharedModule is also not really appealing as I would basically just end up with a giant SharedModule with a other modules effectively only representing views of the application, which would effectively result in a flat app structure.

from angular.

christopherthielen avatar christopherthielen commented on April 20, 2024

Agreed, this is a bug that needs to be fixed

from angular.

christopherthielen avatar christopherthielen commented on April 20, 2024

I'm unable to reproduce this error. Can you please reproduce it for me?

I've got an angular-cli project started here: https://github.com/christopherthielen/foo-is-already-defined

Run ng serve

from angular.

aeternusrahl avatar aeternusrahl commented on April 20, 2024

I believe this is related to this angular issue: angular/angular#13652

from angular.

christopherthielen avatar christopherthielen commented on April 20, 2024

Thanks for posting that. I think we can work around the bug by eliminating duplicates when applying the ng module configs

from angular.

christopherthielen avatar christopherthielen commented on April 20, 2024

@jspizziri I think I have a fix for this, but I can't test it without a reproduction. I'm going to push the change, and when I do will close the issue. If it's not fixed we can reopen.

from angular.

jspizziri avatar jspizziri commented on April 20, 2024

@christopherthielen,

Thanks for working on this! Sorry I wasn't able to get you a reproduction. Once the fix is pushed, I'll make sure to let you know if it does or does not fix the issue in our repository.

Thanks again!

from angular.

Related Issues (20)

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.