2017-08-22 42 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以外,它在任何地方都可以工作,它實際上有很多 –

相關問題