Aurelia - 无法让 CssAnimator 处理简单消息 div
Aurelia - Trouble getting CssAnimator working with simple message div
首先,我使用的是 Typescript 和 this blog post by Mikhail Shilkov。
虽然我使用的是 Typescript,但这个 post 在 Javascript 中,我想知道这是否是它无法正常工作的原因...(请参阅下面的错误)
我在我的页面顶部设置了一个 div,其中包含变量 "test",我已将其链接到一个更改测试值的按钮。
<template>
<require from="./animateOnChange"></require>
<div animateonchange.bind="test">
${test}
</div>
<button click.delegate="testAnimation()" type="button">test Animation</button>
</template>
在视图中:
public test: string = "pears";
testAnimation() {
this.test = "apples";
}
根据 post 我正在使用自定义属性。
我的 AnimateOnChangeCustomAttribute class 在下面,我在这里遇到错误。
import { autoinject, customAttribute } from 'aurelia-framework';
import { CssAnimator } from 'aurelia-animator-css';
@customAttribute('animateonchange')
@autoinject
export class AnimateOnChangeCustomAttribute {
element: any;
constructor(element, public animator: CssAnimator) {
this.element = element;
}
valueChanged(newValue) {
console.log("ELEMENT, NEW VALUE: ", this.element, newValue);
this.animator.addClass(this.element, 'background-animation').then(() => {
this.animator.removeClass(this.element, 'background-animation');
});
}
}
这一行有错误:
this.animator.addClass(this.element, 'background-animation').then(() => {
...说它无法读取未定义的属性 'contains'..
Uncaught (in promise) TypeError: Cannot read property 'contains' of undefined
at aurelia-animator-css.js:373
at new Promise (<anonymous>)
at CssAnimator.addClass (aurelia-animator-css.js:366)
at AnimateOnChangeCustomAttribute.services/messages/animateOnChange.AnimateOnChangeCustomAttribute.valueChanged (animateOnChange.ts:16)
at BehaviorPropertyObserver.selfSubscriber (aurelia-templating.js:3662)
at BehaviorPropertyObserver.call (aurelia-templating.js:3527)
at Controller.bind (aurelia-templating.js:3388)
at View.bind (aurelia-templating.js:1406)
at Controller.bind (aurelia-templating.js:3409)
at View.bind (aurelia-templating.js:1406)
想知道是否有人知道为什么这里失败了?
额外信息
我使用了与博客相同的 css。
.background-animation-add {
-webkit-animation: changeBack 0.5s;
animation: changeBack 0.5s;
}
.background-animation-remove {
-webkit-animation: fadeIn 0.5s;
animation: fadeIn 0.5s;
}
@-webkit-keyframes changeBack {
0% { background-color: white; }
50% { background-color: lightgreen; }
100% { background-color: white; }
}
@keyframes changeBack {
0% { background-color: white; }
50% { background-color: lightgreen; }
100% { background-color: white; }
}
我已将此 css 文件添加到包含此视图模型的“”标签的页面顶部。
<template>
<require from="../navmenu/navmenu"></require>
<require from="../../services/messages/messages"></require>
<require from="./app.css"></require>
<!--We want the nav bar to span the page-->
<div class="container-fluid">
<navmenu router.bind="router"></navmenu>
</div>
<div class="container">
<div className='col-sm-12'>
<div className='row'>
<messages></messages> //HERE IS THE VIEW MODEL.
</div>
<!--We want the media to centre so we use just container-->
<div className='row'>
<router-view></router-view>
</div>
</div>
</div>
</template>
尝试将构造函数更改为:constructor(private element: Element, public animator: CssAnimator)
首先,我使用的是 Typescript 和 this blog post by Mikhail Shilkov。
虽然我使用的是 Typescript,但这个 post 在 Javascript 中,我想知道这是否是它无法正常工作的原因...(请参阅下面的错误)
我在我的页面顶部设置了一个 div,其中包含变量 "test",我已将其链接到一个更改测试值的按钮。
<template>
<require from="./animateOnChange"></require>
<div animateonchange.bind="test">
${test}
</div>
<button click.delegate="testAnimation()" type="button">test Animation</button>
</template>
在视图中:
public test: string = "pears";
testAnimation() {
this.test = "apples";
}
根据 post 我正在使用自定义属性。
我的 AnimateOnChangeCustomAttribute class 在下面,我在这里遇到错误。
import { autoinject, customAttribute } from 'aurelia-framework';
import { CssAnimator } from 'aurelia-animator-css';
@customAttribute('animateonchange')
@autoinject
export class AnimateOnChangeCustomAttribute {
element: any;
constructor(element, public animator: CssAnimator) {
this.element = element;
}
valueChanged(newValue) {
console.log("ELEMENT, NEW VALUE: ", this.element, newValue);
this.animator.addClass(this.element, 'background-animation').then(() => {
this.animator.removeClass(this.element, 'background-animation');
});
}
}
这一行有错误:
this.animator.addClass(this.element, 'background-animation').then(() => {
...说它无法读取未定义的属性 'contains'..
Uncaught (in promise) TypeError: Cannot read property 'contains' of undefined
at aurelia-animator-css.js:373
at new Promise (<anonymous>)
at CssAnimator.addClass (aurelia-animator-css.js:366)
at AnimateOnChangeCustomAttribute.services/messages/animateOnChange.AnimateOnChangeCustomAttribute.valueChanged (animateOnChange.ts:16)
at BehaviorPropertyObserver.selfSubscriber (aurelia-templating.js:3662)
at BehaviorPropertyObserver.call (aurelia-templating.js:3527)
at Controller.bind (aurelia-templating.js:3388)
at View.bind (aurelia-templating.js:1406)
at Controller.bind (aurelia-templating.js:3409)
at View.bind (aurelia-templating.js:1406)
想知道是否有人知道为什么这里失败了?
额外信息 我使用了与博客相同的 css。
.background-animation-add {
-webkit-animation: changeBack 0.5s;
animation: changeBack 0.5s;
}
.background-animation-remove {
-webkit-animation: fadeIn 0.5s;
animation: fadeIn 0.5s;
}
@-webkit-keyframes changeBack {
0% { background-color: white; }
50% { background-color: lightgreen; }
100% { background-color: white; }
}
@keyframes changeBack {
0% { background-color: white; }
50% { background-color: lightgreen; }
100% { background-color: white; }
}
我已将此 css 文件添加到包含此视图模型的“”标签的页面顶部。
<template>
<require from="../navmenu/navmenu"></require>
<require from="../../services/messages/messages"></require>
<require from="./app.css"></require>
<!--We want the nav bar to span the page-->
<div class="container-fluid">
<navmenu router.bind="router"></navmenu>
</div>
<div class="container">
<div className='col-sm-12'>
<div className='row'>
<messages></messages> //HERE IS THE VIEW MODEL.
</div>
<!--We want the media to centre so we use just container-->
<div className='row'>
<router-view></router-view>
</div>
</div>
</div>
</template>
尝试将构造函数更改为:constructor(private element: Element, public animator: CssAnimator)