2017-08-22 40 views
5

我目前正在所有可能的浏览器中测试我的应用程序,并且我看到角动画在Safari iOS 9.3中的行为不像预期的那样。经过几小时 和几小时试图解决它我来请求帮助。提前致谢。Angular 4动画不适用于Safari iOS 9.3

我的代码如下:

的package.json

"dependencies": { 
    "@angular/animations": "^4.3.2", 
    "@angular/cdk": "^2.0.0-beta.8", 
    "@angular/common": "^4.0.0", 
    "@angular/compiler": "^4.0.0", 
    "@angular/core": "^4.0.0", 
    "@angular/forms": "^4.0.0", 
    "@angular/http": "^4.0.0", 
    "@angular/material": "^2.0.0-beta.8", 
    "@angular/platform-browser": "^4.0.0", 
    "@angular/platform-browser-dynamic": "^4.0.0", 
    "@angular/router": "^4.0.0", 
    "@ngx-meta/core": "^0.4.0-rc.2", 
    "@ngx-translate/core": "^7.1.0", 
    "@ngx-translate/http-loader": "^1.0.1", 
    "angular2-moment": "^1.6.0", 
    "core-js": "^2.4.1", 
    "express": "^4.15.4", 
    "lodash": "^4.17.4", 
    "ng2-pdf-viewer": "^1.1.1", 
    "ng2-translate": "^5.0.0", 
    "rxjs": "^5.4.1", 
    "web-animations-js": "^2.3.1", 
    "zone.js": "^0.8.14" 
}, 

landing.component.ts

import { Component, HostBinding, ChangeDetectionStrategy } from '@angular/core'; 
import { stateTransition } from '../routing.animations'; 

@Component({ 
    selector: 'cp-landing', 
    templateUrl: './landing.component.html', 
    styleUrls: ['./landing.component.css'], 
    changeDetection: ChangeDetectionStrategy.OnPush, 
    animations: [ stateTransition() ] 
}) 
export class LandingComponent { 
    @HostBinding('@stateTransition') ''; 
} 

routing.animations.ts

import { trigger, state, animate, style, transition } from '@angular/animations'; 

export function stateTransition() { 
    return trigger('stateTransition', [ 
    state('void', style({ 
     transform: 'translateY(50%)', 
     opacity: 0 
    })), 
    state('*', style({ 
     transform: 'translateY(0%)', 
     opacity: 1 
    })), 
    // enter animation 
    transition('void => *', animate('.5s 500ms')), 
    // exit animation 
    transition('* => void', animate('.5s')) 
    ]); 
} 

我试过了一个小提琴,但我无法重现错误。

回答

1

最后错误是相当太具体的ngx-pdf-viewer文库保持在装载组件的瞬间造成此错误。

我做了什么来解决它,只有当用户在桌面上,我采取了另一种手机方式动态编译组件。

我的代码:

const template = '<pdf-viewer [src]="src"' + 
       '   [show-all]="true"' + 
       '   [zoom]="2">' + 
       '</pdf-viewer>'; 

const tmpCmp = Component({template: template})(class {}); 
const tmpModule = NgModule({ 
    declarations: [tmpCmp, PdfViewerComponent], 
    imports: [CommonModule]} 
)(class {}); 

this._compiler.compileModuleAndAllComponentsAsync(tmpModule) 
.then((factories) => { 
    const f = factories.componentFactories[0]; 
    const cmpRef = f.create(this._injector, [], null, this._m); 
    cmpRef.instance.src = this.data.src; 
    this.pdfViewerContainer.insert(cmpRef.hostView); 
}); 
0

尝试通过使用此版本

"@angular/animations": "4.0.2" 
+0

我做到了这一点,并降低了@ angular/platform-b​​rowser的工作效果,但最终动画完全停止工作。有任何想法吗? html元素只是获得最终所需的属性,但没有任何动画。 –

4

的网络动画API降级包需要在Safari中填充工具,我相信。其默认情况下未启用。您只需安装polyfill,然后在您的应用的/ src文件夹中的polyfills.ts文件中添加一行或两行。

在这里看到:How to add Web Animations API polyfill to an Angular 2 project created with Angular CLI

(复制下面的最佳答案)

添加具有角CLI的更新,的WebPack版的填充工具很容易:

与安装

npm install web-animations-js --save 

添加到polyfills.ts:

require('web-animations-js/web-animations.min'); 

它还工作,如果我做

import 'web-animations-js/web-animations.min'; 
+0

我忘了在问题描述中添加polyfills.ts,但我已经导入了web-animations-js ...除了iphones以外,它在任何地方都可以工作,它实际上有很多 –

相关问题