Angular 2: My component does not work on index

Asked

Viewed 687 times

1

I would like to interpret my component within my index.html, about.html, contact.html, and other pages.

I created the component using Angular cli.

My structure is as follows: Estrutura do meu projeto Angular

The code inside my file app.modulets. is:

import { AppComponent } from './app.component';
import { NavbarModule } from './navbar/navbar.module';



@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    NavbarModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

In my app., I didn’t even move it.

In my file navbar.module.ts this way:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';


import { NavbarComponent } from './navbar.component';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [
    NavbarComponent
  ],
  exports: [
    NavbarComponent
  ]
})
export class NavbarModule { }

Already my file navbar-Components is like this:

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

@Component({
  selector: 'app-navbar',
  templateUrl: './navbar.component.html',
  styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

Inside my navbar.component.html file you have mine that you would like to import in index. And in index.html, I’m trying to call my componenet, but it won’t.

I need some solution, please.

2 answers

1


Enter the tag within the app.component.html that will work.

  • 1

    Yes... then I had to pay attention to the concepts of routes to use the tags. Thank you Guilherme.

0

Use that selector to get her inside In your case, on the line where you want to place the Nav use

<app-navbar></app-navbar>

Browser other questions tagged

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