Angular2 Exception: ngClass within a Host, "isn't a known native property"

Viewed 3108

Is it possible to use "ngClass" within the host for a component/directive.

    @Component({
        selector: 'custom',
        template: `<div [ngClass]="classMap"></div> // I work
        <ng-content></ng-content>`,
        host: {
            '[ngClass]' : 'classMap' // I don't work!!!
        }
    })
    export class CustomComponent {
        constructor () {
            this.classMap = {
                custom: true
            };
        }
    }

In the above example the ngClass works correctly on the div in the template.. it get's a "custom" class added, but it throws an exception when trying to add via to the Host.

"Can't bind to 'ngClass' since it isn't a known native property"

Setting the class in the host directly works fine e.g.;

host: {
    '[class.custom]' : 'classMap.custom'
}

Therefore would think ngClass would be ok? Incorrect syntax? (likely!!!) : )

2 Answers
Related