我正在尝试将我的Angular应用程序部署到heroku。但是,如果我跑
git push heroku master
在编译期间我得到了
remote: ERROR in app/component/login/login.component.ts(24,5): Error during template compile of 'LoginComponent'
remote: Function expressions are not supported in decorators in 'listAnimation'
remote: 'listAnimation' references 'ɵ0'
remote: 'ɵ0' contains the error at app/component/login/login.animation.ts(5,15)
remote: Consider changing the function expression into an exported function.
但我的ɵ0
:
LoginComponent
login.animation.ts
import {
sequence, trigger, stagger, animate, style, group, query as q, transition, keyframes, animateChild,
state
} from '@angular/animations';
const query = (s,a,o={optional:true})=>q(s,a,o);
export const listAnimation = trigger('listAnimation', [
transition(':enter', [
query('.container', style({opacity: 0}), {optional: true}),
query('.container', stagger('150ms', [
animate('150ms ease-in', keyframes([
style({opacity: 0, transform: 'translateY(100%)', offset: 0}),
style({opacity: 1, transform: 'translateY(0)', offset: 1.0})
]))]), {optional: true})
]),
transition('* => loggedIn', [
query('.container', style({opacity: 1}), {optional: true}),
query('.container', stagger('-150ms', [
animate('150ms ease-in', keyframes([
style({opacity: 1, transform: 'translateY(0)', offset: 0}),
style({opacity: 0, transform: 'translateY(100%)', offset: 1.0})
]))]), {optional: true})
])
]);
login.component.ts
import {Component, HostListener, OnInit} from '@angular/core';
import {FormBuilder, Validators} from '@angular/forms';
import {HttpClient} from '@angular/common/http';
import {AuthenticationService} from '../../service/authentication.service';
import {Router} from '@angular/router';
import {NGXLogger} from 'ngx-logger';
import {listAnimation} from './login.animation';
import {Subject} from 'rxjs/Subject';
import {Observable} from 'rxjs/Observable';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css'],
styles: [`
.mat-card {
margin: 5%;
max-width: 300px;
}
.mat-form-field {
width: 100%;
}`],
animations: [
listAnimation
],
host: {
'[@listAnimation]': 'true'
}
})
export class LoginComponent implements OnInit {
viewState: string = 'init';
constructor(private http: HttpClient,
private router: Router, private logger: NGXLogger) { }
ngOnInit(): void {
if (AuthenticationService.isLoggedIn()) {
this.logger.debug('Already logged in. Goto /home.');
this.router.navigate(['/home']);
}
}
onSubmit(): void {
this.viewState = 'loggedIn';
}
animationDone() {
this.logger.info('animationDone');
if (this.viewState == 'loggedIn') {
this.router.navigate(['/home']);
}
}
}
那究竟是什么问题?
我试过替换
const query = (s,a,o={optional:true})=>q(s,a,o);
与
export function query(s, a, o={optional:true}) {
return q(s,a,o);
}
但这也无济于事。
答案 0 :(得分:3)
正如您的错误所示,您需要导出该功能。装饰者不接受对其属性的函数调用。
您可以找到有关此github问题的更多信息:https://github.com/angular/angular/issues/15587
答案 1 :(得分:3)
在我的情况下,错误是由以下原因引起的:
export const listAnimation = ()...
代替:
export function listAnimation()...
答案 2 :(得分:0)
您需要像这样重构代码:
{
provide: APP_INITIALIZER,
useFactory: loadStuff,
deps: [InitRolesService],
multi: true
}
然后导出功能
export function loadStuff(service: InitService) {
return () => service.load().subscribe(data => { ... }));
}