Code Monkey home page Code Monkey logo

angular_modules's Introduction

Sandbox

I created this project to duplicate an Issue I've been having with angular modules. The issue is as follows:

  • I have 3 Modules
    • AppModule
    • a SharedModule that declares/exports a SharedComponent that's needed Globally, and is declared in AppModule
    • a FeatureModule that is also declared in AppModule
  • I have a component in FeatureModule (at route '/feature') that needs access to SharedComponent, which should be available because it's imported by AppModule by-way-of SharedModule. But When I go to the route, i get this error:
Uncaught Error: Template parse errors:
'app-shared-component' is not a known element:
1. If 'app-shared-component' is an Angular component, then verify that it is part of this module.
2. If 'app-shared-component' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. (" declared by FeatureModule.</h1>
    <p>I need Access to Shared Component from SharedModule</p>
    [ERROR ->]<app-shared-component></app-shared-component>
  "): ng:///FeatureModule/FeatureComponent.html@3:4
    at syntaxError (compiler.js:1021)
  • In the larger App I'm working on, this problem is "solved" by importing the SharedModule into the FeatureModule as well as the AppModule. But when I do that I get THIS error:
Uncaught Error: Type SharedComponent is part of the declarations of 2 modules: SharedModule and FeatureModule! Please consider moving SharedComponent to a higher module that imports SharedModule and FeatureModule. You can also create a new NgModule that exports and includes SharedComponent then import that NgModule in SharedModule and FeatureModule.
    at syntaxError (compiler.js:1021)

So it seems like a no-win situation.

Solution: I'd been declaring the module twice. Had to move it up to imports. That sorted it.

References

Here are some of the many articles I've looked at in trying to find an answer to this problem:

angular_modules's People

Contributors

jessicabarnett avatar

Watchers

James Cloos avatar  avatar

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.