Inject owner into class

Home   »   Inject owner into class

import { setOwner } from '@ember/application';
import { inject as service } from '@ember/service';

import Service from '@ember/service';


export default class MyClass extends Service {
  @service myService;
  
  appName = this.myService.appName;
}
import Controller from '@ember/controller';
import { getOwner } from '@ember/application';
import { tracked } from '@glimmer/tracking';
import MyClass from '../classes/my-class';

export default class ApplicationController extends Controller {
  @tracked appName;

  constructor() {
    super(...arguments);
    
    this.appName = new MyClass(getOwner(this) ).appName;
  }
}
import Service from '@ember/service';

export default class MyService extends Service {
  appName = 'Ember Twiddle';
}

Leave a Reply

Your email address will not be published. Required fields are marked *