[英]Aurelia activate function never be called
我使用Aurelia + WebStorm编写了一个工具栏。 在此工具栏中,有一个激活功能,但永远不会自动调用它。 您可以在此处查看TypeScript代码:
import {autoinject} from "aurelia-dependency-injection";
import {RouteConfig, Router} from "aurelia-router";
import {bindable} from "aurelia-templating";
import {getLogger} from "aurelia-logging";
import {ActuatorApi, NotificationApi, SystemApi} from "gen/api";
@autoinject
export class HeaderBar {
private static LOG = getLogger("header-bar");
public notificationKey: string;
...
@bindable
public router: Router;
constructor(private actuatorApi: ActuatorApi, private notificationApi: NotificationApi,
private systemApi: SystemApi) {
this.isBatterieTestActive = true;
this.hrefForActuatoresList = "#/app/configuration/actuators/";
this.loadActuators();
}
public async activate(params: any, routeConfig: RouteConfig): Promise<void> {
return this.loadNotifications();
}
请你帮助我好吗?
您可能要尝试对组件而不是附加组件使用Activate方法。 例如:
export class HeaderBar {
private async attached(): Promise<void> {
return await this.loadNotifications();
}
private loadNotifications() {
// do your async stuff here...
console.log('yeej, it works!');
}
}
与原始代码段相比,有一些变化:
在Aurelia文档的“ 组件生命周期”部分中还更全面地描述了activate()的用法。
更新:对于Aurelia生命周期中的差异,StackOverflow问题“ Aurelia中的组件和视图之间的差异(及其生命周期)”也可能引起关注。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.