dimanche 26 avril 2020

Ember & Typescript - how to inject router service

I am trying to inject RouterService into my controller:

import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import RouterService from '@ember/routing/router-service';


export default class Search extends Controller.extend({
  // anything which *must* be merged to prototype here
}) {
    @service router!: RouterService;


    @action
    actionClick(){
        this.router.transitionTo('protected.apk.detail')
    }
}

// DO NOT DELETE: this is how TypeScript knows how to look up your controllers.
declare module '@ember/controller' {
  interface Registry {
    'search': Search;
  }
}

but I get an error: Error: Assertion Failed: Attempting to inject an unknown injection: 'service:router' I guess it's because there is not service:router, but router:main instead. Can you advise me, how to properly inject RouterService? This controller is in my engine. ember version: 3.18.0

thank you




Aucun commentaire:

Enregistrer un commentaire