Skip to content

Instantly share code, notes, and snippets.

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();
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