これも可能です。このgetStateメソッドをapp.componentに追加するだけです。
app.component.tsテンプレートで
export class AppComponent {
getState(outlet) {
return outlet.activatedRouteData.state;
}
}
は、変更イベントにルータの新しい状態を取得する必要があります。今、あなたのコンポーネントでアニメーションがあなたのページを区別することができます
app.component.html
<main [@routerTransition]="getState(o)">
<router-outlet #o="outlet"></router-outlet>
</main>
。
次にあなたが
trigger("routerTransition", [
transition("* => settings", slideLeft),
transition("settings => *", slideRight),
])
あなたtransistionsを持つことができますしかし、あなたのルータがデータ
{
path: "settings",
component: SettingsComponent,
data: { state: "settings" }
}
を送信する必要があるそして、あなたのアニメーションが今特徴とすることができる:
query(":enter",
[
style({
transform: "translateX(100%)"
}),
animate("0.4s ease-in-out",
style({
transform: "translateX(0%)"
})
)
], {
optional: true
}
),
query(":leave",
[
style({
transform: "translateX(0%)"
}),
animate("0.4s ease-in-out",
style({
transform: "translateX(-100%)"
})
)
], {
optional: true
})
パッケージを残す:入力し、 .json
{
"name": "health",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"core-js": "^2.4.1",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "1.4.8",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "~3.2.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.3.3"
}
}
はい私は午後にこれを試しましたが、私がそうすると、このタイプのエラーが発生します:_synthetic property @routerTransition。 「BrowserAnimationsModule」_ を含めるようにしてください。私は、私のapp-moduleにBrowserAnimationsModuleをインポートしました。だから私はなぜこのエラーがあるのか分からない。 – zarnifoulette
すみません。私はこのエラーを知らない。私はあなたが望んだのと同じことを達成しようとしていました、そして、これは私のための完璧な方法でした。ブラウザ、BrowserAnimationsModule、AppRoutingModule、RouterModuleモジュールをapp-moduleにインポートしてインポートに追加しましたか?あなたはapp.componentにクエリ、アニメーション、スタイル、そしてインポートとして使うすべてのものが必要です – BO41
はい、私はすべて私の依存関係やキャッシュをきれいにします。私の問題を解決することを願っています。 ありがとうございます! – zarnifoulette