解决 Angular2/Ionic2 微信动画报错问题
正确的代码,错误的信息废话不说,看代码! import {Component,trigger,state,style,animate,transition} from '@angular/core';
@Component({
templateUrl: 'build/pages/animations/animations.com.html',animations: [trigger("animationState",[
state("fuck",style({
transform: "scale(1)"
})),state("noFuck",style({
transform: "scale(1.5)"
})),transition('fuck => noFuck',animate('100ms cubic-bezier(1,1.5,1)')),transition('noFuck => fuck',animate('100ms ease-out'))
])]
})
export class AnimationsPage{
private state: string = "fuck";
public constructor(){
}
public onButtonClick(){
if(this.state == "fuck"){
this.state = "noFuck";
}
else{
this.state = "fuck"
}
}
}
animations.com.html: <ion-header>
<ion-navbar>
<ion-title>Animations动画</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding text-center>
<img @animationState="state" (click)="onButtonClick()" src="https://www.baidu.com/img/baidu_jgylogo3.gif" />
<p>请点击Logo</p>
</ion-content>
很简单有木有?!Chrome、Safari、Android的WebKit都好用,可到了微信X5浏览器上,报错!!! 通过微信提供的调试工具,捕捉到如下错误信息: EXCEPTION: Error in build/pages/animations/animations.com.html:7:9 browser_adapter.js:93
EXCEPTION: Error in build/pages/animations/animations.com.html:7:9 browser_adapter.js:84
ORIGINAL EXCEPTION: TypeError: undefined is not a function browser_adapter.js:84 ORIGINAL STACKTRACE: browser_adapter.js:84 TypeError: undefined is not a function at WebAnimationsPlayer.play (http://192.168.1.177:8100/build/js/app.bundle.js:46354:69) at AnimationSequencePlayer.play (http://192.168.1.177:8100/build/js/app.bundle.js:24708:79) at DebugAppView.AppView.registerAndStartAnimation (http://192.168.1.177:8100/build/js/app.bundle.js:31893:16) at AnimationsPage_animationState_0_factory (AnimationsPage.template.js:34:8) at DebugAppView._View_AnimationsPage0.detectChangesInternal (AnimationsPage.template.js:190:5) at DebugAppView.AppView.detectChanges (http://192.168.1.177:8100/build/js/app.bundle.js:32060:14) at DebugAppView.detectChanges (http://192.168.1.177:8100/build/js/app.bundle.js:32165:44) at DebugAppView.AppView.detectViewChildrenChanges (http://192.168.1.177:8100/build/js/app.bundle.js:32086:19) at DebugAppView.AppView.detectChangesInternal (http://192.168.1.177:8100/build/js/app.bundle.js:32071:14) at DebugAppView.AppView.detectChanges (http://192.168.1.177:8100/build/js/app.bundle.js:32060:14) browser_adapter.js:84 ERROR CONTEXT: browser_adapter.js:84 DebugContext {_view: _View_AnimationsPage0,_nodeIndex: 11,_tplRow: 7,_tplCol: 9,_staticNodeInfo: (...)…}
初步怀疑报错是『动画』引起,因为我啥也没写啊… 尝试歪打正着,在Angular2的官方网站发现[动画章节] 有两句话提到:
死马当活马医,从github上download了一份web-animations-js,并加入到我的index.html中。 奇迹出现了!不会再报错,动画也播放正常! 解决方案打入Web Animations API的兼容补丁即可
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |