import { Component } from '@angular/core';
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
@Component({
selector: 'style-sample-app',
template: `
This is never bordered
This is always bordered
Using object literal. Border {{ isBordered ? "ON" : "OFF" }}
Using object var. Border {{ classesObj.bordered ? "ON" : "OFF" }}
This will always have a blue background and
round corners
This is {{ classList.indexOf('blue') > -1 ? "" : "NOT" }} blue
and {{ classList.indexOf('round') > -1 ? "" : "NOT" }} round
`
})
export class NgClassSampleApp {
isBordered: boolean;
classesObj: Object;
classList: string[];
constructor() {
this.isBordered = true;
this.classList = ['blue', 'round'];
this.toggleBorder();
}
toggleBorder(): void {
this.isBordered = !this.isBordered;
this.classesObj = {
bordered: this.isBordered
};
}
toggleClass(cssClass: string): void {
var pos: number = this.classList.indexOf(cssClass);
if (pos > -1) {
this.classList.splice(pos, 1);
} else {
this.classList.push(cssClass);
}
}
}
@NgModule({
declarations: [ NgClassSampleApp ],
exports: [ NgClassSampleApp ],
imports: [ BrowserModule ]
})
export class NgClassSampleAppModule {}