【发布时间】:2018-10-03 22:37:58
【问题描述】:
我在谷歌上搜索了如何做我想做的事情并尝试了一些东西,但没有任何效果,我发现了很多 AngularJS 教程但不是 Angular6.. 所以我希望你能帮助我。
我想在我的数组值发生变化时淡化(点击)所以我下载了 ng-animate 但它没有给我我正在寻找的行为。 目前,我有两个组件,所以第一个:
HTML:
<div style="text-align: center; margin: 20px 0">
<div class="buttonSelector" *ngFor="let select of buttonSelector" (click)="getSelectArray(select.title)"
[ngClass]="{'selected': select.title === selectedArray.title.toUpperCase() }">
<p>{{ select.title }}</p>
</div>
</div>
<app-infoapp [selectedArray]="selectedArray"></app-infoapp>
在那里,我通过将变量发送到 getSelectArray() 来更改我的 selectedArray,然后将其发送到我的“app-infoapp”组件。 在我的“app-infoapp”组件中,我们可以找到:
import {Component, Input, OnInit} from '@angular/core';
import { trigger, transition, useAnimation } from '@angular/animations';
import {bounce, fadeIn} from 'ng-animate';
@Component({
selector: 'app-infoapp',
templateUrl: './infoapp.component.html',
styleUrls: ['./infoapp.component.css'],
animations: [
trigger('fade', [transition('* => *', useAnimation(fadeIn, {delay: 0.2}))])
]
})
export class InfoappComponent implements OnInit {
@Input() selectedArray;
fade: any;
constructor() {
}
}
所以现在当我刷新我的页面时,组件正在褪色,这很酷,但是当我通过单击按钮更改我的数组以便将另一个数组发送到我的“app-infoapp”组件时,它不会再次动画.
我希望我很清楚,你能帮助我。
如果您需要更多信息或者如果我不清楚,请告诉我,我会尽快回答。
谢谢。
【问题讨论】:
-
Angular 2 带有自己的动画模块“@angular/animations”,你可以找到很多关于它的很棒的教程,并通过不透明度更改实现动画的淡入淡出。例如:kdechant.com/blog/angular-animations-fade-in-and-fade-out
-
首先,感谢您的回答。我尝试按照教程进行操作,但遇到了同样的问题:当我重新加载页面时动画清晰可见,但是当我通过单击按钮更改已发送数组的值时,它不会再次设置动画: /
标签: javascript html angular typescript web