0

I learned angular 2, but I can't do a multiple component, for exemple I try this and is doesen't work :

app.module.ts :

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

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

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

app.component.ts :

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

@Component({
    moduleId: module.id,
    selector: 'my-app',
    templateUrl: './app.component.html'
})

export class AppComponent  {}

test.component.ts :

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

@Component({
    moduleId: module.id,
    selector: 'test',
    templateUrl: './test.component.html'
})

export class TestComponent {}

app.component.html :

<h1>Hello World!</h1>

test.component.html :

<h2>test</h2>
2
  • 2
    Can you show us, what you did in ./app.component.html? It would work if you have specified test inside AppComponent html.. Commented Jan 15, 2017 at 13:54
  • 3
    Do you want your test component to display inside your app component? If so, add <test></test> to app.component.html Commented Jan 15, 2017 at 14:10

1 Answer 1

1

You have to "call" the test component from the app.

And in Angular 2, it is done with html tag selectors.

If you add <test></test>

in app.component.html, it should render the test component.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.