I created the following simple example component that adds some attributes and a listener to the component's DOM element using the host property for the @Component decorator. In my case, [ngClass] is not valid. Does anyone know why and how to fix it?
import {Injector, Component} from "angular2/core"; import {NgClass} from "angular2/common"; import {SelectionService} from "../selection-service" @Component({ selector: 'my-component', template: `<div>inner template</div>`, host: { 'style': 'background-color: yellow', // works '[ngClass]': "{'selected': isSelected}", // does not work '(mouseover)': 'mouseOver($event)', // works '(mouseleave)': 'mouseLeave($event)' // works }, directives: [NgClass] }) export class MyComponent { private isSelected = false; constructor(private selectionService:SelectionService) { this.selectionService.select$.subscribe((sel:Selection) => { this.isSelected = sel; // has no effect on ngClass }); } mouseOver($event) { console.log('mouseOver works'); } mouseLeave($event) { console.log('mouseLeave works'); } }
I am using Angular 2.0.0-beta.7.
source share