【问题标题】:NativeScript Angular 5 Animations not doing anythingNativeScript Angular 5 Animations 没有做任何事情
【发布时间】:2018-01-29 08:09:51
【问题描述】:

我正在使用带有 Angular 5 的 NativeScript。

"tns-core-modules": "~3.4.0",
"nativescript-angular": "~5.2.0",
"@angular/animations": "~5.2.0",

我正在尝试让动画正常工作,但我根本无法让任何事情发生。甚至没有任何错误。

这是我的应用的布局方式:

app.module:

@NgModule({
bootstrap: [
    AppComponent
],
imports: [
    CoreModule,
    AppRoutingModule
],
declarations: [
    AppComponent
]
})

导入具有动画导入的 CoreModule:

const MODULES: any[] = [
NativeScriptModule,
NativeScriptFormsModule,
NativeScriptHttpModule,
NativeScriptAnimationsModule
];

@NgModule({
imports: [
    ...MODULES,

我所有其余的模块都是延迟加载的。例如,我的 NotificationsModule 如下所示:

 @NgModule({
imports: [
    SharedModule,
    NotificationsRoutingModule

SharedModule 有:

   imports: [
    NativeScriptCommonModule,
    NativeScriptModule,
    NativeScriptRouterModule,
    NativeScriptFormsModule,
    TNSFontIconModule,
],

现在在我的 notifications.component.html 中:

   <Label [@mystate]="'in'"

在ts文件中:

 animations: [
    trigger('mystate', [
        state('in', style({
            'opacity': 1,
            transform: 'scale(1) rotate(0)'
        })),
        state('void', style({
            'opacity': 0,
            transform: 'scale(0) rotate(-1300)'
        })),
        // 'after a delay of 1000ms, show an animation with a duration of 2300ms'
        transition('void => *', [animate('2300ms 1000ms ease-out')])
    ]),

所以这个标签应该在页面加载后立即进行一系列旋转。但是什么也没有发生。我有什么遗漏吗?

为了添加更多内容,我尝试了其他动画进入和离开,但我也无法触发它们:

     trigger('visibilityChanged', [
        transition(':enter', [
            style({ opacity: 0, transform: 'translateX(-40px)' }),
            animate(600, style({ opacity: 1, transform: 'translateX(0)' }))
        ]),
        transition(':leave', [
            style({ opacity: 1, transform: 'translateX(0)' }),
            animate(600, style({ opacity: 0, transform: 'translateX(-40px)'
            }))
        ])
    ])

HTML:

    <StackLayout [@visibilityChanged] *ngIf="shouldBeVisible" row="1" colSpan="3" class="dropdown-wrapper m-t-4">
            <Label text="test"></Label>
        </StackLayout>

【问题讨论】:

    标签: angular nativescript angular5 angular-animations


    【解决方案1】:

    您显然是从 this repo 借来的代码,您可以在本地克隆它以见证它确实有效(或从应用商店下载)。

    所述应用目前使用的是 Angular 4,因此可能存在一些差异,但至少它不是标题所暗示的 NativeScript 限制。

    【讨论】:

    • 是的,我从那个仓库借来的,因为我正在尝试了解它是如何工作的。我已经下载了那个应用程序,它当然可以工作;我通过那个 repo 完成了大部分 NativeScript 学习。虽然我只使用动画部分,所以我们的应用程序非常不同并且有不同的情况。就我而言,此动画代码在本地对我不起作用。这是我的应用程序的一个限制,因为我做错了什么而无法正常工作。因此,我在问是否有人能发现我做错了什么。附言我觉得你评论我的帖子很酷。你所有的 nativescript 内容对我帮助很大。
    猜你喜欢
    • 2017-12-08
    • 2012-09-07
    • 2016-10-02
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多