Target Problem of Angular Components 2 with importing external Javascripts

Asked

Viewed 178 times

0

I have a problem and I believe it is related to the scope of Components in Angular 2.

First of all, I would like to comment on the division of the project. It is divided into five components, the App, Menu-left, Menu-header, Content and Footer-Component.

Index:

<html>
  <head>
    <meta charset="utf-8">
    <title>Frontend</title>
    <base href="/">
    <meta name="viewport" content="width=device-width, initial-scale=1">
  </head>
  <body class="nav-md">
    <div class="container body">
        <div class="main_container">
          <app-root></app-root>
        </div>
    </div>
  </body>
</html>

The <app-root></app-root> is the principal and consists of the modules:

app.component.ts:

<menu-left></menu-left>
<menu-header></menu-header>
<content></content>
<footer-component></footer-component>

Inside each one is an HTML content that will be presented to the user, with the top menu (menu-header), a menu on the left (menu-left), etc...

The problem I’m having is in relation to the loading of Javascript in the presentation of this data, IE, Javascripts work for the Menu-Header, in which a menu drop-down with the effects 100%. However, the same does not occur for the Menu-Left, where there is also a menu drop-down.

What I tested was the following: I joined all the Htmls (from menu-left, menu-header, content, footer) and inserted them directly on the main page (index.html) and the most frustrating thing was that everything worked, with 100% of the effects loaded from the Javascripts that I imported.

Note that I am using Angular-CLI and I am importing Styles and Javascripts as follows:

angular-cli.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "frontend"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "../../../target/frontend",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/gentelella/vendors/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/gentelella/vendors/font-awesome/css/font-awesome.min.css",
        "../node_modules/gentelella/vendors/iCheck/skins/flat/green.css",
        "../node_modules/gentelella/vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css",
        "../node_modules/gentelella/production/css/maps/jquery-jvectormap-2.0.3.css",
        "../node_modules/gentelella/production/less/custom.css"        
      ],
      "scripts": [
        "../node_modules/gentelella/vendors/jquery/dist/jquery.min.js",
        "../node_modules/gentelella/vendors/bootstrap/dist/js/bootstrap.min.js",
        "../node_modules/gentelella/build/js/custom.min.js"
    ...
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "css",
    "component": {}
  }
}

I would like a suggestion that can help me to find this problem that I believe is 'scoped', because it made me most sense.

Valeeu!!

  • Alexandre, all right? <br> Did you import and declared the Components in the "app.module"? <br> I had a similar problem yesterday, when I went to review the code, I realized that I had not imported and declared a component.

  • Yes, I imported the modules and added them to Imports. .

  • Alexandre, in the declarations of "app.module.ts" you need to declare the new components too, for example, this: "@Ngmodule({ declarations: [ Appcomponent, Helloworldcomponent, Useritemcomponent, Userlistcomponent, Articlecomponent ]"

  • Actually no, because I already include the modules of the same and when I enter again, there is a Compilation error, showing that I am setting twice the.

  • @Alexandrebarreironeto put there in the post the app.module.ts

No answers

Browser other questions tagged

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