Angular2: Component host property

angular

What does @Component.host property stand for?

According to Angular2 documentation it stands for:

host – map of class property to host element bindings for events, properties and attributes.

I don't quite figure out what's it for?

I'm posing this in order to understand a stuff code I've stuck last days.

The code is:

@Component({
  selector: 'layout',
  encapsulation: ViewEncapsulation.None,
  templateUrl: './layout.template.html',
  host: {
    '[class.nav-static]' : 'config.state["nav-static"]',
    '[class.chat-sidebar-opened]' : 'chatOpened',
    '[class.app]' : 'true',
    id: 'app'
  }
})
export class Layout {

Best Answer

I have added class to host tag.

Like following:

  • Component

    @Component({
      selector: 'mytag',
      templateUrl: './layout.template.html',
      host: {
        'class' : 'myclass1 myclass2 myclass3'
      }
    })
    export class MyTagComponent {
    
  • View code

    <mytag></mytag>

  • Result

    <mytag class="myclass1 myclass2 myclass3"></mytag>