Angular2在模型更改时设置动画

Angular2在模型更改时设置动画,angular,angular2-components,angular2-animation,Angular,Angular2 Components,Angular2 Animation,我有一个组件PageComponent,它的数据在不同的url上更新。我想在页面模型更改时设置动画。在我给出的示例中,动画仅在加载PageComponent时第一次工作 更新模型时,我应该添加/更改哪些动画才能工作 page.component.ts 我也有同样的问题,我用文章中描述的步骤解决了它。基本上,您需要执行3个步骤: 导入ChangeDetectorRef类 import { ChangeDetectorRef } from "@angular/core"; 使用依赖项注入创建此

我有一个组件
PageComponent
,它的数据在不同的url上更新。我想在
页面
模型更改时设置动画。在我给出的示例中,动画仅在加载
PageComponent
时第一次工作

更新模型时,我应该添加/更改哪些动画才能工作

page.component.ts


我也有同样的问题,我用文章中描述的步骤解决了它。基本上,您需要执行3个步骤:

  • 导入ChangeDetectorRef

    import { ChangeDetectorRef } from "@angular/core";
    
  • 使用依赖项注入创建此类的实例

    constructor(private changeDetector: ChangeDetectorRef) {}
    
  • 在更改后对ChangeDetectorRef类的实例调用方法detectChanges()

    // Change your model ...
    SomeMethodWhichChangesTheModel();
    
    // ... and call the detectChanges() method on the ChangeDetectorRef
    this.changeDetector.detectChanges();
    
  • constructor(private changeDetector: ChangeDetectorRef) {}
    
    // Change your model ...
    SomeMethodWhichChangesTheModel();
    
    // ... and call the detectChanges() method on the ChangeDetectorRef
    this.changeDetector.detectChanges();