Following the Angular 2 Animation Documentation ( https://angular.io/docs/ts/latest/guide/animations.html ), I switched to Angular 4.0.1. Here is part of my .json package:
"@angular/common": "~4.0.1",
"@angular/compiler": "~4.0.1",
"@angular/core": "~4.0.1",
"@angular/forms": "~4.0.1",
"@angular/http": "~4.0.1",
"@angular/platform-browser": "~4.0.1",
"@angular/platform-browser-dynamic": "~4.0.1",
"@angular/router": "~4.0.1",
"@angular/animations": "~4.0.1",
"typescript": "^2.2.2",
"zone.js": "^0.8.4"
system.config.js
'@angular/animations': 'npm:@angular/animations/bundles/animations.umd.js',
'@angular/animations/browser': 'npm:@angular/animations/bundles/animations-browser.umd.js',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser/animations': 'npm:@angular/platform-browser/bundles/platform-browser-animations.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule, Title } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
...
@NgModule({
imports: [ BrowserModule, BrowserAnimationsModule, appRouting, FormsModule ],
...
})
Inside my custom component, I also imported Angular animations:
import { trigger, state, style, animate, transition } from '@angular/animations';
And my view (the look assigned by templateUrl!) Looks like this:
<div class="container" [@containerState]="showContainer">
...
</div>
Problem: I always get a console error message:
Error: Unprepared (in promise): Error: Synthetic property @containerState was found. Please include "BrowserAnimationsModule" or "NoopAnimationsModule" in your application.
When I remove this synthetic property, everything works fine, but I cannot use Angular Animations.
? angular -cli!
container.component.ts
import { Component, OnInit, OnDestroy, EventEmitter, HostListener, Input, Output } from '@angular/core';
import { trigger, state, style, animate, transition } from '@angular/animations';
@Component({
templateUrl: '...',
selector: '...',
animations: [
trigger('containerState', [
state('hide', style({transform: 'translateY(-102%)'})),
transition('hide => show', [
animate(500, style({transform: 'translateY(0)'}))
]),
transition('show => hide', [
animate(500, style({transform: 'translateY(-102%)'}))
])
])
]
})
...
? node_modules . . ! Angular 2.x Angular 4.x