In angular 2 I am trying to use @angular/animations
to make a component where a <li>
element follows the mouse (ondrag)
and stays in position after (ondragend)
. I am quite new to angular and very lost on what the best way to tackle this problem is. I would like to be able to inject a string from my component back into the animations but am not sure if this is possible. See an example below.
import { Component } from '@angular/core';
import { trigger, state, style, animate, transition } from '@angular/animations';
@Component({
selector: 'test-test',
template: `
<li
*ngFor="let letter of list"
[@lettereState]="letter.state"
(ondrag)="letter.toggleState(); mouseCords($event.clientX, $event.clientY);"
(ondragend)="letter.toggleState()">
{{letter}}
</li> `,
animations: [
trigger('letterState', [
state('active', style({
transform: //'translate(Inject the cordinates here {mouseX}, {mouseY})',
})),
])
],
})
export class LetterBankComponent {
constructor(
) {}
private list = ['a', 'b', 'c']
private mouseX = ''
private mouseY = ''
}
mouseCords(x, y) {
mouseX = x;
mouseY = y;
}
In terms of injecting data into animations it is a feature request and coming soon maybe (see https://github.com/angular/angular/issues/9668). In terms of having a draggable element adding
[draggable]
to an element seems to solve this problem