Hamid
Hamid

Reputation: 249

my component does not shown in index page

i'm starter and i'm trying create a simple component in angular but i have problem, my component does not shown in index page please help me..

this is my component with "List.Component.ts" name :

import { Component } from '@angular/core';

@Component({
  selector:'navBar',
  templateUrl:'./navBarTemplate.html'
})

export class navBar {
  constructor(){

  }
}

this is my template html code :

<ul>
  <li>Test-1</li>
  <li>Test-2</li>
  <li>Test-3</li>
</ul>

And i imported my component in the "app.module.ts" file:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';


import { AppComponent }  from './app.component';

//here is my component
import { navBar } from './List.Component';


@NgModule({
  imports:      [ BrowserModule ],
  declarations: [ AppComponent, navBar ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

but angular just shown "Hello Angular" in the index page.

my Index page :

<!DOCTYPE html>
<html>
  <head>
    <title>Angular QuickStart</title>
    <base href="/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles.css">

    <!-- Polyfill(s) for older browsers -->
    <script src="node_modules/core-js/client/shim.min.js"></script>

    <script src="node_modules/zone.js/dist/zone.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>

    <script src="systemjs.config.js"></script>
    <script>
      System.import('main.js').catch(function(err){ console.error(err); });
    </script>
  </head>

  <body>
    <NavBar></NavBar>
    <my-app>Loading AppComponent content here ...</my-app>
  </body>
</html>

Upvotes: 2

Views: 469

Answers (5)

ashkan
ashkan

Reputation: 580

To solve your problem, you need to use the following tag :

<navBar>
           ...
</navBar>

Upvotes: 1

Surjeet Bhadauriya
Surjeet Bhadauriya

Reputation: 7156

Just add <navBar></navBar> in the app.component.html.

And add <router-outlet></router-outlet> below navbar so that other component can be viewed.

app.component.html

<navBar></navBar>
<router-outlet></router-outlet>

Upvotes: 1

briosheje
briosheje

Reputation: 7436

<body>
    <NavBar></NavBar>
    <my-app>Loading AppComponent content here ...</my-app>
</body>

Your entire application is wrapped inside my-app. The outer part of it is not aware of what <navBar> is, unless the web component is declared and compiled elsewhere.

In a nutshell, you need to wrap <navBar> (beware of initial n lowercase) inside any component inside your angular application. For instance, you can place it inside AppComponent, which is likely where you wanted it to be.

Upvotes: 2

UI_Dev
UI_Dev

Reputation: 3417

In your index.html file, remove navbar selector and use the below navbar selector in app.component.html file

<navBar></navBar>

Upvotes: 1

Adrita Sharma
Adrita Sharma

Reputation: 22213

You need to add <NavBar></NavBar> in app.component.html

Upvotes: 1

Related Questions