[英]Is state change possible in animation triggers without any click event?
my animation trigger has three states: Void, True and false. 我的动画触发器具有三种状态:无效,正确和错误。
I am using a subscription to check if there is a change in one of the variables. 我正在使用订阅检查变量之一是否发生更改。 If there is a change, state changes to true and popup appears as per the following animation:
如果进行了更改,则状态更改为true,并根据以下动画显示弹出窗口:
animations: [
trigger('visibilityChanged', [
state('void' , style({ opacity: 0})),
state('true' , style({ opacity: 1})),
state('false', style({ opacity: 0})),
transition('* => *', animate('.5s'))
])
]
I want this popup to disappear after a short time (1s) without triggering any click event or change. 我希望此弹出窗口在短时间内(1s)后消失,而不会触发任何点击事件或更改。
You could use a Subject for your subscription and then subscribe two times to it : 您可以使用主题进行订阅,然后订阅两次:
This is an example : 这是一个例子:
import {Component, OnInit} from '@angular/core';
import {Subject} from 'rxjs/Subject';
@Component({
selector: 'selfclosing-popup',
templateUrl: 'etc.'
animations: [
trigger('visibilityChanged', [
state('void' , style({ opacity: 0})),
state('true' , style({ opacity: 1})),
state('false', style({ opacity: 0})),
transition('* => *', animate('.5s'))
])
]
})
export class SelfclosingPopup implements OnInit {
changeSubject = new Subject<boolean>();
visibilityChanged: string;
ngOnInit(): void {
this.changeSubject.subscribe((change) => this.visibilityChanged = change);
this.changeSubject.debounceTime(1000).subscribe(() => this.visibilityChanged = false);
}
public notifyChange() {
this.changeSubject.next(true);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.