Uso tipografico & angolare 2.0.0-rc.4animazione angular2 con stili variabili
Come posso specificare i valori delle proprietà di stile dal modello in modo che possa utilizzare i pulsanti ri-? Ad esempio, se volessi specificare un colore di sfondo diverso per ciascun pulsante in base a una proprietà associata al modello. Vedi sotto
assumere i seguenti componenti:
import {
Component,
OnInit,
OnDestroy,
Input,
style,
state,
animate,
transition,
trigger
} from '@angular/core';
@Component({
selector: 'my-toggle-button',
template: `<div @state="state" (click)="click()">{{bgColor}}</div>`,
animations: [
trigger('state', [
state('inactive', style({
'color': '#606060'
})),
state('active', style({
'color': '#fff',
'background-color': '#606060' // I want this to be bgColor
})),
transition('inactive <=> active', animate('100ms ease-out'))
])
]
})
export class ToggleButtonComponent implements OnInit {
@Input() bgColor: string;
state: string = 'inactive';
active: boolean = false;
ngOnInit() {
this.state = this.active ? 'active' : 'inactive';
}
click() {
this.active = !this.active;
this.state = this.active ? 'active' : 'inactive';
}
}
chiamando modello:
<h1>Animated Directive</h1>
<my-toggle-button [bgColor]="'#f00'"></my-toggle-button>
<my-toggle-button [bgColor]="'#0f0'"></my-toggle-button>
<my-toggle-button [bgColor]="'#00f'"></my-toggle-button>
http://plnkr.co/edit/KBO2pgS8B0lSAPLIf0Js?p=preview
Si può venire con plunker se sarebbe bello per aiutarti. – micronyks
Ho modificato il mio post con un plnkr – nograde