按 ID 獲取並顯示使用者名稱

import {User} from 'backend/user'; // import custom class
import {inject} from 'aurelia-framework'; // allows us to inject

@inject(User) // inject custom class
export class ProfileView {
  constructor(user) { // use instance of custom class as a parameter to the constructor
    this.user = user; // save instance as a an instance variable
    this.username = '';
  }

  activate(params) {
    // call function from custom class, then save the result as another instance variable
    return this.user.getUsernameById(param.user_id)
      .then(user => this.username = user.username);
  }
}