我對使用相同組件路徑的動畫有問題。例如。我有這樣的路線:相同組件之間的角度4動畫
{路徑: '產品/分類/:類',成分:CategoryComponent},
首先我解決了一個問題,路線PARAMS,因爲他們無法刷新ngOnit()功能,當我在相同的組件之間導航。但是現在我已經將動畫添加到了我的應用程序中,並且如果從HomeComponent轉到CategoryComponent,則完美無瑕。但是,如果我從不同的參數從CategoryComponent到CategoryComponent,動畫不起作用。
這裏我的動畫文件:
import { animate, AnimationEntryMetadata, state, style, transition, trigger } from '@angular/core';
// Component transition animations
export const slideInDownAnimation: AnimationEntryMetadata =
trigger('routeAnimation', [
state('*',
style({
opacity: 1,
transform: 'translateX(0)'
})
),
transition(':enter', [
style({
opacity: 0,
transform: 'translateX(-100%)'
}),
animate('0.5s ease-in')
]),
transition(':leave', [
animate('0.5s ease-out', style({
opacity: 0,
transform: 'translateY(100%)'
}))
])
]);
在這裏,我CategoryComponent.ts
import { Component, OnInit, EventEmitter,Input, Output,HostBinding} from '@angular/core';
import { Pipe, PipeTransform } from '@angular/core';
import {FirebaseService} from '../../services/firebase.service';
import { AngularFireDatabase, FirebaseListObservable,FirebaseObjectObservable} from 'angularfire2/database';
import {Router, ActivatedRoute, Params,ParamMap} from '@angular/router';
import * as firebase from 'firebase';
import { Observable } from 'rxjs';
import {Subject} from 'rxjs';
import { routerTransition } from '../../router.animations';
import { slideInDownAnimation } from '../../animations';
import { FlashMessagesService } from 'angular2-flash-messages';
@Component({
host: {
'[@routeAnimation]': 'true'
},
selector: 'app-category',
templateUrl: './category.component.html',
styleUrls: ['./category.component.css'],
animations: [ slideInDownAnimation ]
})
export class CategoryComponent implements OnInit {
@HostBinding('@routeAnimation') routeAnimation = true;
@HostBinding('style.display') display = 'block';
@HostBinding('style.position') position = 'absolute';
products:any;
search:any;
imageUrls:any = [];
imgSelected: any;
counter:any;
image:any;
images:any;
myimage:any;
count:any;
sub:any;
i:any;
category:any;
fakeimage:any;
constructor(
private firebaseService: FirebaseService,
private router:Router,
public af:AngularFireDatabase,
private route:ActivatedRoute,
private flashMessage:FlashMessagesService) {
}
ngOnInit() {
this.counter = 0;
var params;
this.sub = this.route.paramMap
.switchMap((params: ParamMap) =>
this.firebaseService.getProductsByCategory(params.get('category'))).subscribe(products => {
this.products = products;
this.count = products.length;
});;
}
returnImage(key,url){
this.imageUrls.push(new ImageUrl(key,url));
}
searchProps(){
this.firebaseService.getProductsByTitle(this.search.toLowerCase()).subscribe(products => {
this.products = products;
});
}
getProductsByTitle(title){
console.log('here');
this.firebaseService.getProductsByTitle(title.toLowerCase()).subscribe(products => {
this.products = products;
});
}
getImageUrl(prodid) {
// Go call api to get poster.
var data = '';
var that = this;
this.firebaseService.getProductImages(prodid).subscribe(images => {
this.image = images[0];
var img = this.image;
if(this.image != null){
let storageRef = firebase.storage().ref();
let spaceRef = storageRef.child(this.image.path);
storageRef.child(img.path).getDownloadURL().then(function(url) {
that.returnImage(img.$key,url);
}).catch(function(error) {
// Handle any errors
});
}
});
}
ngOnDestroy() {
this.sub.unsubscribe();
}
}
export class ImageUrl {
url: string;
id:string;
constructor(public _id:string,public _url: string) {
}
}
任何想法,我能做些什麼嗎?
謝謝。
你是國王的傢伙。感謝您的幫助。現在我再次有動力繼續我的應用程序。 – Francisco
嗨@Francisco - 這是如何解決問題 - 你不可能手動添加所有可能的類別路線(或者你可以?) – Ryan