0

Here i am trying to create a simple angular application. I have created one more component named tutorialcomponent, than app component. Now using selector of tutorialComponent, i am trying to embed it in app component. But i am not getting output of app component after embedding. here is my app component:

import { Component } from '@angular/core';
import {TutorialComponent} from './tutorial/tutorial.component';

@Component({
  selector: 'app-root',
  template: `./app.component.html
        <app-tutorial></app-tutorial>`,
  styleUrls: ['./app.component.css']
})  
export class AppComponent {
  title = 'My Angular2 Login App';
}

Here is tutorialcomponent,

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

@Component({
  selector: 'app-tutorial',
  templateUrl: './tutorial.component.html',
  styleUrls: ['./tutorial.component.css']
})
export class TutorialComponent  {


}

Here is my output,

enter image description here

so please suggest me a way to bind components.

2
  • 1
    The selector would be app-tutorial and templateUrl, not template, would identify the html content. Commented Dec 14, 2017 at 10:23
  • <app-tutorial> is selector for for tutorial component. My code for tutorial component is import { Component } from '@angular/core'; @Component({ selector: 'app-tutorial', templateUrl: './tutorial.component.html', styleUrls: ['./tutorial.component.css'] }) export class TutorialComponent { } Commented Dec 14, 2017 at 10:28

3 Answers 3

1

Try this

import { Component } from '@angular/core';
import { TutorialComponent } from './tutorial/tutorial.component';

@Component({
   selector: 'app-root',
   template: `{{ title }} <br/>
              <app-tutorial></app-tutorial>`,
   styleUrls: ['./app.component.css']
})  

export class AppComponent {
   public title = 'My Angular2 Login App'; //define as public 
}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

@Component({
  selector: 'app-root',
  template: `{{title}}<br><app-tutorial></app-tutorial>`,  //this line
  styleUrls: ['./app.component.css']
})  

I think your app component is working as expected. You are not binding the title that's wht you are not able to see the message.

Comments

0

Or if you prefer to have an html file you can try this:

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['./app.component.css']
})  

Puis dans le fichier html tu remets ceci:

<span>{{title}}</span>
<br>
<app-tutorial></app-tutorial>

1 Comment

Thank-you. Its working for my application. Both the components are displaying on browser now.

Your Answer

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