Reputation: 1478
I programmed a tool-bar using Aurelia + WebStorm. In this tool-bar there is an activate function but it never be called automatically. You can see the TypeScript code here:
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();
}
Could you please help me?
Upvotes: 2
Views: 1851
Reputation: 9532
You might want to try using the activate method for a component, instead of attached. For example:
export class HeaderBar {
private async attached(): Promise<void> {
return await this.loadNotifications();
}
private loadNotifications() {
// do your async stuff here...
console.log('yeej, it works!');
}
}
Some changes in comparison to your original snippet:
The usage of activate() is also described more thoroughly in the Component Lifecycle section of the Aurelia docs.
Update: For the difference in Aurelia lifecycles, the StackOverflow question "Difference between a Component and a View in Aurelia (and their lifecycle)" may be of interest as well.
Upvotes: 4