Set the Angular 2 component/app in the <body> tag

Asked

Viewed 58 times

1

I would like to define the tag <body> as root of my Angular 2 application instead of creating a daughter tag <my-app> (for example).

1 answer

0


Define body as the root component selector of your application.

Something like

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

@Component({
    selector: 'body',
    template: '<h1>{{mensagem}}</h1>'
})
export class AppComponent { 
    String mensagem = "Minha primeira aplicação Angular 2";
}
  • My doubt is just this. In the previous version, Angularjs, this was very intuitive because we used a directive as an attribute of the ex tag: <body ng-app="my-app">...</ body>. Already in Angular 2, so I have seen so far the application or component is the tag itself as I have shown before: <my-app>...</ my-app>

  • Unless you want to win award for minimalism, could you explain better the solution you are giving? Thank you! :)

  • @Edgardamasceno edited the answer

  • 1

    Very good, @merchant ! It was exactly what I was looking for but there was no attempt to define the component.

Browser other questions tagged

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