Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aurelia code quality - part 5
import {inject} from 'aurelia-framework';
import {EventAggregator} from 'aurelia-event-aggregator'; //import the EventAggregator class
import {GreeterService} from './services/greeter-service.js';
@inject(GreeterService, EventAggregator)
export class Greeter{
constructor(greeterService, eventAggregator){
this.greeterService = greeterService;
this.eventAggregator = eventAggregator;
}
attached(){ //called when the greeter component is attached to the DOM
this.greetings = this.greeterService.loadGreetings();
}
addGreeting(){
this.greetings.add(this.greeting); //add a new greeting to the list
this.eventAggregator.publish(`greeting-added`, this.greeting);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.